时时商务社区

标题: 解析PHP实现下载文件的两种方法 [打印本页]

作者: wx_pylelnL4    时间: 2018-2-14 08:15

            方法一:
[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);
方法二:
[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();
            
            
您可能感兴趣的文章:
  • 解决PHP超大文件下载,断点续传下载的方法详解
  • 解析如何在PHP下载文件名中解决乱码的问题
  • 解析php多线程下载远程多个文件
  • 解析php下载远程图片函数 可伪造来路
  • 解析获取优酷视频真实下载地址的PHP源代码
  • php对csv文件的读取,写入,输出下载操作详解
  • php 下载保存文件保存到本地的两种实现方法
  • 使用PHP下载CSS文件中的图片的代码
  • php 强制下载文件实现代码
  • php使浏览器直接下载pdf文件的方法
  • php实现文件下载(支持中文文名)
  • php读取csv实现csv文件下载功能
  • php下载excel无法打开的解决方法
  • PHP IE中下载附件问题解决方法
  • PHP 下载文件时自动添加bom头的方法实例
  • 使用PHP强制下载PDF文件示例
  • 分享一个超好用的php header下载函数
  • php实现下载限制速度示例分享
            




    欢迎光临 时时商务社区 (http://bbs.4435.cn/) Powered by Discuz! X3.2