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");
?>

相关文章

PHP5.2下preg_replace函数的问题

preg_replace 使用的超过了php5.2默认允许的字节,也就是pcre.backtrack_limit和pcre.recursion_limit的大小的问题。 Discuz!6...

php动态生成版权所有信息的方法

本文实例讲述了php动态生成版权所有信息的方法。分享给大家供大家参考。具体实现方法如下: function copyright($start, $owner) { $date = d...

PHP经典实用正则表达式小结

本文实例讲述了PHP经典实用正则表达式。分享给大家供大家参考,具体如下: 对于开发人员来说,正则表达式是一个非常有用的功能,它提供了 查找,匹配,替换 句子,单词,或者其他格式的字符串。...

php 移除数组重复元素的一点说明

如:复制代码 代码如下:$test_array=array(1,2,3,4,4,5,5,6); $test_array_unique=array_unique($test_array);...

分享一个漂亮的php验证码类

本文实例为大家分享了一个漂亮的php验证码类,供大家参考,具体内容如下 //验证码类 class ValidateCode { private $charset = 'abcdef...