本篇文章是對使用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();
From:http://tw.wingwit.com/Article/program/PHP/201311/21007.html