php 强制下载文件实现代码

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?php
$file = 'monkey.gif';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
?>
?
<?php
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=ins.jpg"); 
readfile("imgs/test_Zoom.jpg");
?>

相关文章

php从csv文件读取数据并输出到网页的方法

本文实例讲述了php从csv文件读取数据并输出到网页的方法。分享给大家供大家参考。具体实现方法如下: <?php $fp = fopen('sample.csv','r...

如何使用PHP实现javascript的escape和unescape函数

前端开发工程师都知道javascript有编码函数escape()和对应的解码函数unescape(),而php中只有个urlencode和urldecode,这个编码和解码函数对enc...

php中get_meta_tags()、CURL与user-agent用法分析

本文实例分析了php中get_meta_tags()、CURL与user-agent用法。分享给大家供大家参考。具体分析如下: get_meta_tags()函数用于抓取网页中<m...

PHP操作MongoDB实现增删改查功能【附php7操作MongoDB方法】

本文实例讲述了PHP操作MongoDB实现增删改查功能。分享给大家供大家参考,具体如下: MongoDB的PHP驱动提供了一些核心类来操作MongoDB,总的来说MongoDB命令行中有...

php实现给图片加灰色半透明效果的方法

本文实例讲述了php实现给图片加灰色半透明效果的方法。分享给大家供大家参考。具体实现方法如下: 原理: 1.首先计算出原图片的尺寸 2.创建相同尺寸的半透明图片 3.使用 imageco...