解析PHP实现下载文件的两种方法_php教程-查字典教程网
解析PHP实现下载文件的两种方法
解析PHP实现下载文件的两种方法
发布时间:2016-12-29 来源:查字典编辑
摘要:方法一:复制代码代码如下:header('Content-Description:FileTransfer');header('Conten...

方法一:

复制代码 代码如下:

header('Content-Description: File Transfer');

header('Content-Type: application/octet-stream');

header('Content-Disposition: attachment; filename='.basename($filepath));

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($filepath));

readfile($file_path);

方法二:

复制代码 代码如下:

$fileinfo = pathinfo($filename);

header('Content-type: application/x-'.$fileinfo['extension']);

header('Content-Disposition: attachment; filename='.$fileinfo['basename']);

header('Content-Length: '.filesize($filename));

readfile($thefile);

exit();

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新php教程学习
    热门php教程学习
    编程开发子分类