【发布时间】:2012-11-10 21:27:30
【问题描述】:
可能重复:
php, file download
我有一些不在 Web 根目录中的文件,我需要将其提供给下载。所以我有一个脚本,它使用下面的来下载请求的文件。问题是,我下载的每个文件都损坏了?文件没问题,因为如果我使用 FTP 下载,它们就会打开。以下是传递的标头:
header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
header("Cache-Control: public"); // needed for i.e.
header("Content-Type: " . $download[0]['mime']);
header("Content-Disposition: attachment; filename=" .$download_file);
header("Content-Transfer-Encoding: Binary");
header("Content-Length:".filesize($attachment_location));
readfile($attachment_location);
【问题讨论】: