解析PHP实现下载文件的两种方法
程序员文章站
2022-06-01 19:02:50
方法一:复制代码 代码如下: header('content-description: file transfer'); header('content...
方法一:
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();
复制代码 代码如下:
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();