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使用标准库spl实现的观察者模式示例

本文实例讲述了PHP使用标准库spl实现的观察者模式。分享给大家供大家参考,具体如下: 前面使用纯php实现了一个观察者模式(php观察者模式), 现在使用php标准库spl在次实现观察...

PHP字符串逆序排列实现方法小结【strrev函数,二分法,循环法,递归法】

本文实例总结了PHP字符串逆序排列实现方法。分享给大家供大家参考,具体如下: 关于字符串的逆序排列,最简单的使用PHP函数strrev()的测试代码如下: header('Conte...

解决php中Cannot send session cache limiter 的问题的方法

今天在使用php 的session 的时候,出现了以前就遇见但是又解决不了的问题,在页面上出现如下提示: Warning: session_start()&...

php上传文件并显示上传进度的方法

本文实例讲述了php上传文件并显示上传进度的方法。分享给大家供大家参考。具体如下: 记得上传文件的时候要大点,不然还没看出来就上传完了,并且上传的文件不要太大,上G的就算了,2G的我试了...

php+ajax无刷新分页实例详解

本文实例讲述了php+ajax无刷新分页实现方法。分享给大家供大家参考,具体如下: ajax_page_show_userinfo.php页面如下: <meta 'Conten...