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//========================== 定义redirect() 开始 =========================///**...

php中__destruct与register_shutdown_function执行的先后顺序问题

根据php手册的解析。 __destruct是 析构函数会在到某个对象的所有引用都被删除或者当对象被显式销毁时执行。 而register_shutdown_function是 Regis...

php中final关键字用法分析

本文实例讲述了php中final关键字用法。分享给大家供大家参考,具体如下: final关键字只能用来定义类和定义方法。 使用final关键字标记的类不能被继承 final clas...

解决nginx不支持thinkphp中pathinfo的问题

解决nginx不支持thinkphp中pathinfo的问题

下面小编通过文字加代码的方式给大家详解下,具体内容如下: 其实,要解决nginx不支持pathinfo的问题,有两个解决思路,一是不使用pathinfo模式,二是修改nginx的配置文件...

从康盛产品(discuz)提取出来的模板类

复制代码 代码如下: <?php /*template.class.php @康盛微博 模板提取类 觉得这个模板好用 花些时间独立出来。 by 雷日锦 @看了一下ctt 这个模板...