php强制下载文件函数
2013-05-29 16:25
225 查看
有些类型文件(如txt,dat等),浏览器打开是默认是直接打开内容,也许你使用了<a href="url"></a>,但是浏览器才不管你那一套,照样直接打开。
我想实现直接下载怎么办:一下是php下载文件函数:
function downloadFile($file){
/*Coded by Alessio Delmonti*/
$file_name = $file;
$mime = 'application/force-download';
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
header('Content-Transfer-Encoding: binary');
header('Connection: close');
readfile($file_name); // push it out
exit();
}
我想实现直接下载怎么办:一下是php下载文件函数:
function downloadFile($file){
/*Coded by Alessio Delmonti*/
$file_name = $file;
$mime = 'application/force-download';
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
header('Content-Transfer-Encoding: binary');
header('Connection: close');
readfile($file_name); // push it out
exit();
}
相关文章推荐
- php强制下载文件函数
- php强制下载文件函数
- php强制文件下载而非在浏览器打开的自定义函数分享
- php强制文件下载而非在浏览器打开的自定义函数分享
- 记录一个php强制下载文件函数
- php进行文件的强制下载
- php中强制下载文件的代码(解决了IE下中文文件名乱码问题)
- PHP header()函数实现文件下载功能
- php下载文件源代码(强制任意文件格式下载)
- php header函数下载文件实现代码
- PHP自定义函数: 下载远程文件
- PHP代码实现远程下载文件到本地的函数
- PHP强制下载文件
- PHP下载文件的函数实例代码
- php 强制下载文件实现代码
- PHP备份数据库生成SQL文件并下载的函数代码
- [PHP实例] PHP 强制文件下载
- php简单实现文件或图片强制下载的方法
- php后端强制前端下载文件