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构造方法中析构方法在继承中的表现

本文为大家分享了php构造方法之析构方法在继承中的表现,供大家参考,具体内容如下 子类中没有定义构造方法时,会自动调用父类的构造方法。因此实例化子类时,需按照父类的构造方法的形式进行。...

在PHP中使用curl_init函数的说明

复制代码 代码如下: $ch = curl_init(); $c_url = 'http://www.baidu.com'; $c_url_data = "product_&type="...

php chr() ord()中文截取乱码问题解决方法

复制代码 代码如下:<?php $lenth = 19; $str = "怎么将新闻的很长的标题只显示前面一些字,后面用.....来代替?"; echo strlen($str)&...

浅谈php的TS和NTS的区别

ts(Thread-Safety)即线程安全,多线程访问时,采用了加锁机制,当一个线程访问该类的某个数据时,进行保护,其他线程不能进行访问直到该线程读取完,其他线程才可使用。不会出现数据...

PHP5.3与5.5废弃与过期函数整理汇总

很多PHP程序员都知道,从PHP5.3开始加入了一个新的报错级别DEPRECATED,即将废弃/过期。下面我们来一个个版本梳理一下。 在php5.3被放弃的函数有: call_us...