我是靠谱客的博主 英勇毛衣,这篇文章主要介绍解析PHP实现下载文件的两种方法,现在分享给大家,希望可以做个参考。

方法一:

复制代码 代码如下:

 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实现下载文件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(118)

评论列表共有 0 条评论

立即
投稿
返回
顶部