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代码出现错误分析详解第1/2页

错误类型: 一、未使用二进制上传   代码:    Fatal error: This encoded&n...

高级php注入方法集锦第1/2页

'%23  ' and passWord='mypass  id=-1 union select 1,1,1&nbs...

PHP文件读写操作相关函数总结

PHP文件读写操作相关函数总结

一、fwrite()写入文件 将程序中的数据保存到文件中比较容易,使用fwrite()函数就可以将字符串内容写入文件中。在文件中中通过字符序列\n表示换行符,表示文件中一行的末尾。当需要...

搭建自己的PHP MVC框架详解

本文详细讲述了搭建自己的PHP MVC框架的方法。分享给大家供大家参考,具体如下: 前言 说到写PHP的MVC框架,大家想到的第一个词--“造轮子”,是的,一个还没有深厚功力的程序员,写...

PHP异常类及异常处理操作实例详解

本文实例讲述了PHP异常类及异常处理操作。分享给大家供大家参考,具体如下: 异常处理归类于错误处理,PHP从5.1.0开始增加了Exception异常处理类。 一、异常处理 PHP 异常...