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文件管理基本功能简单操作

(1)先要想好要操作哪个文件? (2)确定文件的路径? (3)要有什么文件管理功能? 一、先做一下简单的查看文件功能,文件中的文件和文件夹都显示,但是双击文件夹可以显示下一级子目录,双击...

phpMyAdmin出现无法载入 mcrypt 扩展,请检查PHP配置的解决方法

1、没有正确安装Mysql数据库,在系统服务中Mysql相关的服务没有启动 (请查看正确安装Mysql的方法) 2、在系统的 system32(C:\windows\system32)...

php中\r \r\n \t的区别示例介绍

\n 软回车: 在Windows 中表示换行且回到下一行的最开始位置。相当于Mac OS 里的 \r 的效果。 在Linux、unix 中只表示换行,但不会回到下一行的开始位置。 \r...

php去掉字符串的最后一个字符附substr()的用法

php去掉字符串的最后一个字符附substr()的用法

今天项目中用到,去掉字符串中的最后一个字符 原字符串1,2,3,4,5,6, 去掉最后一个字符",",最终结果为1,2,3,4,5,6 代码如下: 复制代码 代码如下: $str = "...

php小经验:解析preg_match与preg_match_all 函数

正则表达式在 PHP 中的应用在 PHP 应用中,正则表达式主要用于:•正则匹配:根据正则表达式匹配相应的内容•正则替换:根据正则表达式匹配内容并替换•...