php 强制下载文件实现代码

yipeiwu_com5年前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实现的简单缓存类。分享给大家供大家参考。具体如下: cache.inc.php: <?php class Cache { /** * $di...

php若干单维数组遍历方法的比较

复制代码 代码如下: <?php //a $arr=array('a'=>'abc','b'=>123,'c'=>true); //b //$arr=range(...

php strtotime 函数UNIX时间戳

如果 time 的格式是绝对时间则 now 参数不起作用。如果 time 的格式是相对时间则其所相对的时间由 now 提供,或者如果未提供 now 参数时用当前时间。失败时返回 -1。...

php面向对象编程self和static的区别

在php的面向对象编程中,总会遇到 class test{ public static function test(){ self::func(); static::fu...

php面向对象程序设计入门教程

本文实例讲述了php面向对象程序设计。分享给大家供大家参考,具体如下: 1.面向对象与面向过程的对比 面向过程:以事件为中心,分几个步骤去完成。不可扩展,html与php不分离 面向对象...