我正试图在Mac OS x服务器上的apache web服务器中安装x_sendfile。安装后一切似乎都很好,httpd.conf配置为"LoadModule xsendfile_module libexec/apache2/mod_xsendfile.so"和"XSendFile ON"。
如果我从终端运行"httpd-M",我可以在列表中使用"xsendfile_module(shared)"。
但在phpinfo()或apache_get_modules()中,没有列出x-sendfile。如果我试图在php代码中使用x-sendfile来下载任何文件,浏览器只会下载一个0kb的文件。不过,我可以在头数据中看到x-sendfile头标记。
有什么建议吗?
我在CentOS上遇到了类似的问题。我补充道:
XSendFile On
XSendFilePath /dir-where-the-file-gets-downloaded-from/
到httpd.conf
,但是我也确保在PHP页面本身上使用绝对路径
header('Content-Type: '.$formatMIME);
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=User_sees_this.pdf");
header("X-Sendfile: 'absolute_path_goes_here'");
据我所知,httpd -M
是否显示模块已安装,上面的代码应该可以工作。您不会在phpinfo
中看到xsendfile
,因为它不是PHP的扩展。我不能和apache_get_modules()
通话。
同样,这是一个基于我个人经验的评论,并不是一个明确的答案。
确保httpd.conf
文件中有这一行。将其添加到页面设置下:
<Directory "/var/www/html">
XSendFile On
XSendFilePath /dir-where-the-file-gets-downloaded-from/
<Directory>