Category Archives: 我的代码

我的作品

使用PHP下载文件

使用PHP下载文件方法很多,比较常用的就是使用函数:readfile。演示代码如下: 代码一: header(‘Content-Description: File Transfer’); header(‘Content-Type: application/octet-stream’); header(‘Content-Disposition: attachment; filename=’.basename($file_path)); 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($file_path)); readfile($file_path); 代码二: $fileinfo = pathinfo($thefile); header(‘Content-type: application/x-’.$fileinfo['extension']); header(‘Content-Disposition: attachment; filename=’.$fileinfo['basename']); header(‘Content-Length: ‘.filesize($thefile)); readfile($thefile); exit;

Posted in 我的代码 | Tagged | Leave a comment