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自动适应范围的分页代码

复制代码 代码如下:<?php function page($page,$total,$phpfile,$pagesize=10,$pagelen=7){  &...

彻底杜绝PHP的session cookie错误

只要你写过PHP代码,相信都遇上过这个大多时候都令人莫明其妙的warning吧..今天我们就来搞定它...............   看了PHP手册,回答如下:   消息“Warnin...

浅析PHP中的字符串编码转换(自动识别原编码)

复制代码 代码如下:/** * 对数据进行编码转换 * @param array/string $data     ...

不支持fsockopen但支持culr环境下下ucenter与modoer通讯问题

所以就怀疑是否编码问题,或者文件权限问题,或者是不是函数不支持问题,经过排查发现原来是万网的L1主机不支持fsockopen,在文件uc_client/client.php中的uc_fo...

PHP实现通过URL提取根域名

PHP根据URL提取根域名,个人工作中用到,由于网络上很多代码都不能得到正确结果就自己写了一个,欢迎大家使用并提出其中的bug. <?php #使用示例 echo g...