本篇文章是对使用PHP实现下载文件的两种方法进行了详细的分析介绍
需要的朋友参考下
方法一
复制代码 代码如下:
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:
′);
header(
Cache
Control: must
revalidate
post
check=
pre
check=
′);
header(
Pragma: public
);
header(
Content
Length:
filesize($filepath));
readfile($file_path);
方法二
复制代码 代码如下:
$fileinfo = pathinfo($filename);
header(Contenttype: application/x$fileinfo[extension]);
header(ContentDisposition: attachment; filename=$fileinfo[basename]);
header(ContentLength: filesize($filename));
readfile($thefile);
exit();