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 fputcsv命令 写csv文件遇到的小问题(多维数组连接符)

php fputcsv命令 写csv文件遇到的小问题(多维数组连接符)

命令: fputcsv() 命令格式:int fputcsv ( resource handle [, array fields [, string delimiter [, strin...

浅谈php正则表达式中的非贪婪模式匹配的使用

通常我们会这么写: 复制代码 代码如下: $str = "http://www.baidu/.com?url=www.sina.com/"; preg_match("/http:(.*)...

PHP执行linux系统命令的常用函数使用说明

system函数 说明:执行外部程序并显示输出资料。 语法:string system(string command, int [return_var]); 返回值: 字符串 详细介绍:...

国外十大最流行的PHP框架排名

国外十大最流行的PHP框架排名

以下为十个目前最流行的基于MVC设计模式的PHP框架。 1. Yii Yii是一个基于组件的高性能的PHP的框架,用于开发大规模Web应用。Yii采用严格的OOP编写,并有着完善的库...

PHP如何得到当前页和上一页的地址?

$_SERVER['HTTP_REFERER'] //可以得到上一页的地址  $_SERVER[PHP_SELF] //得到当前页面地址  $_S...