源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

解析PHP实现下载文件的两种方法

  • 时间:2021-05-08 20:34 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:解析PHP实现下载文件的两种方法
[b]方法一: [/b]
[u]复制代码[/u] 代码如下:
 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);
[b]方法二: [/b]
[u]复制代码[/u] 代码如下:
 $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();
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部