【发布时间】:2011-08-20 18:35:43
【问题描述】:
我安装了mod_xsendfile,好像成功了; xsendfile.load 出现在 /etc/apache2/mods-enabled 中,我在运行测试脚本时没有发现任何错误。但是,每次我运行它时,都会得到一个 0B 文件。
这是我的测试脚本:
$file = 'sample.mp4';
$path = '/var/storage/media/'.$file;
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header("Content-type: application/octet-stream");
header("X-Sendfile: $path");
很明显,我有一个文件存储在 /var/storage/media/sample.mp4 中,它只有 25MB,如果我这样做的话,效果会非常好:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($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($path));
ob_clean();
flush();
readfile($path);
exit;
我在 /var/storage 和 /var/www 的 .htaccess 文件中也有这个(包含所有这些的文件都存储在 /var/www/files/index.php 中):
XSendFile on
XSendFileAllowAbove on
就像我说的那样,我没有收到任何错误,PHP 可以肯定地访问该文件,但我必须在 x-sendfile 配置中遗漏一些东西……这提醒了我,我注意到几乎每个 mod 都启用了 mods有.load和.conf,但xsendfile只有.load,但其他几个也有,那和它有什么关系吗?
谢谢。
【问题讨论】:
-
当你说你没有收到错误时,这是否意味着你已经尝试过 "tail -f /var/log/apache2/errors.log"
-
我通读了它,没有发现任何与它试图加载的文件有关的东西。发现很多关于它的条目试图获取我尚未创建的 favicon 文件。
-
嘿,是的,我也收到了那个图标错误
标签: php apache2 download x-sendfile