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基于DOM创建xml文档的方法示例

本文实例讲述了PHP基于DOM创建xml文档的方法。分享给大家供大家参考,具体如下: DOM创建xml文档 用dom创建如下文档: <booklist>   <bo...

PHP会话操作之cookie用法分析

本文实例分析了PHP cookie用法。分享给大家供大家参考,具体如下: 会话技术:cookie 允许服务器端脚本在浏览器存储数据的技术, 允许服务器向浏览器发送指令,用来管理存储在浏...

php5.4以上版本GBK编码下htmlspecialchars输出为空问题解决方法汇总

从旧版升级到php5.4,恐怕最麻烦的就是htmlspecialchars这个问题了!当然,htmlentities也会受影响,不过,对于中文站来说一般用htmlspecialchars...

五个PHP程序员工具

Phing - 一个项目构建系统 Phing 是一个基于Apache ANT 的项目构建系统。它的名字是一个拗口的语句首字母缩写&nbs...

PHP iconv 函数转gb2312的bug解决方法

iconv( "UTF-8", "gb2312//IGNORE" , $FormValues['a']) ignore的意思是忽略转换时的错误,发现iconv在转换字符"—"到gb231...