首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >X-SendFile在centos上不起作用

X-SendFile在centos上不起作用
EN

Stack Overflow用户
提问于 2013-07-03 21:30:03
回答 1查看 1.8K关注 0票数 0

我在6美分上有以下安装。

代码语言:javascript
复制
apache version :Apache 2.0
httpd-tools-2.2.15-28.el6.centos.x86_64
httpd-devel-2.2.15-28.el6.centos.x86_64
httpd-2.2.15-28.el6.centos.x86_64 .

在httpd.conf中,我添加了一行: LoadModule xsendfile_module /usr/lib64/httpd/modules/mod_xsendfile.so

和apache_get_modules();显示加载的mod数组中的mod_xsendfile ...现在我有了包含以下内容的.htaccess文件

代码语言:javascript
复制
<Files files.php>
XSendFile on
</Files>

而files.php有

代码语言:javascript
复制
$path='fileliste.txt';
$documentMIME="text/plain";
$modules = apache_get_modules();
if (in_array("mod_xsendfile", $modules)) {
header ("X-Sendfile: ". $path);
header ("Content-Type: " . $documentMIME);
//header ('Content-Disposition: attachment; filename="textfile"');
}

每件事似乎都是正确的。但是它仍然没有显示任何文件。

EN

回答 1

Stack Overflow用户

发布于 2013-07-09 17:47:37

在.htacess文件中

代码语言:javascript
复制
<Files files.php>
  XSendFile on
</Files>

而files.php是

代码语言:javascript
复制
<?php

 $file = "path_to_your_file";
 $finfo = new finfo;  
  $mime = $finfo->file($file, FILEINFO_MIME_TYPE );
 if (in_array('mod_xsendfile', apache_get_modules()))
 {
header("X-Sendfile: $file");
header("Content-type: $mime");
//header ('Content-Disposition: attachment; filename="image"'); 
 }

?>

不要忘了为.htaccess更改cofig AllowOverride All

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17449376

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档