手机
当前位置:查字典教程网 >编程开发 >php教程 >解析PHP实现下载文件的两种方法
解析PHP实现下载文件的两种方法
摘要:方法一:复制代码代码如下: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实现下载文件的两种方法】相关文章:

Yii实现自动加载类地图的方法

php解析字符串里所有URL地址的方法

PHP实现文件安全下载

php实现统计网站在线人数的方法

php简单实现多字节字符串翻转的方法

PHP遍历数组的方法汇总

开发大型PHP项目的方法

php循环table实现一行两列显示的方法

PHP获取数组的键与值方法小结

用PHP实现文件上传

精品推荐
分类导航