Dou*_*son 5 php apache2 x-sendfile download
我安装了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");
Run Code Online (Sandbox Code Playgroud)
显然我有一个存储在/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;
Run Code Online (Sandbox Code Playgroud)
我也在/ var/storage和/ var/www的.htaccess文件中有这个(所有这些文件都存储在/var/www/files/index.php中):
XSendFile on
XSendFileAllowAbove on
Run Code Online (Sandbox Code Playgroud)
就像我说的,我没有错误,并且PHP可以认证访问该文件,但我必须丢失一些x-sendfile配置......这让我想起,我注意到mods-enabled几乎每个mod都有.加载和.conf,但xsendfile只有.load,但其他一些,所以它与它有什么关系?
谢谢.
我有同样的问题,这个解决方案对我有用:
安装模块后,您需要启用它并为Apache配置提供访问路径(httpd.conf用于全局配置,或特定站点vhost用于特定配置),如下所示:
# enable xsendfile
XSendFile On
# enable sending files from parent dirs
XSendFilePath /var/www/
Run Code Online (Sandbox Code Playgroud)
当然,你必须用你希望xsendfile访问的任何文件夹替换'/ var/www /'
| 归档时间: |
|
| 查看次数: |
6663 次 |
| 最近记录: |