手机
当前位置:查字典教程网 >编程开发 >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简单实现多字节字符串翻转的方法

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

PHP调用三种数据库的方法(3)

PHP实现多线程的两个方法

PHP文本数据库的搜索方法

PHP实现文件安全下载

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

用PHP实现文件上传二法

用PHP实现文件上传

精品推荐
分类导航