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 XML操作的各种方法解析(比较详细)

PHP XML操作的各种方法解析(比较详细)

XML是一种流行的半结构化文件格式,以一种类似数据库的格式存储数据。在实际应用中,一些简单的、安全性较低的数据往往使用 XML文件的格式进行存储。这样做的好处一方面可以通过减少与数据库的...

PHP中require和include路径问题详解

1 绝对路径、相对路径和未确定路径 相对路径 相对路径指以.开头的路径,例如 复制代码 代码如下: ./a/a.php (相对当前目录)    ../c...

解析PHP 5.5 新特性

PHP5.5 前不久前刚刚发布,里面的新特性有什么?官方文档在这里:http://www.php.net/manual/zh/migration55.new-features.php1...

使用PHP socke 向指定页面提交数据

在jquery里用 load post 等等,无法得到我想要的结果!于是突然-----这几天想的东西都白想了,现在只好这样了 现在想在php里面向指定的页面...

php中Ioc(控制反转)和Di(依赖注入)

先看一个例子: <?php class A { public $b; public $c; public function A() { //TODO }...