XSendfile不工作 - PHP,Apache的,交友 [英] XSendfile not working - PHP, Apache, Cpanel

查看:336
本文介绍了XSendfile不工作 - PHP,Apache的,交友的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直强烈推荐使用XSendfile,因为我们是从我们的服务器提供相当大的文件。服务器运行的是交友。 previously我们用的是直力下载脚本,这也是在某些浏览器没有工作。希望能一箭双雕,一石与XSendfile。

I have been strongly recommended to use XSendfile since we are serving quite large files from our server. The server is running Cpanel. Previously we were using a straight force-download script, which also did not work well in some browsers. Hoping to kill two birds with one stone with XSendfile.

行,所以,我们的主机已启用Xsendfile我们的服务器上。我写了一个快速测试脚本:

OK so, our host has enabled Xsendfile on our server. I wrote a quick test script:

$file = "/home/deli/central/testfile.doc";
header("X-Sendfile: $file");
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
exit;

当我运行它,我得到的下载提示。但是,发送的文件总是0KB

When I run this, I get the download prompt. But the file that is sent is always 0kb.

研究了一下,看来你需要设置不同的事情无论是在Apache的配置文件,或htaccess文件。我还被告知,这不是将其添加到Apache的配置是一个好主意,否则可能会被覆盖的最新情况。我宁愿做它htaccess的ayway,因为我没有直接访问Apache的配置,我宁愿控制与htaccess的做它应该提供。

A bit of research, seems you need to set up various things in either the apache config file, or an htaccess file. I was also told that it is not a good idea to add it to the apache config, else it may get overwritten on an update. I would rather do it in htaccess ayway, since I don't have direct access to the apache config and I would rather have the control that doing it with htaccess should offer.

如果我能得到它的工作,当然。

IF I can get it to work, of course.

所以,我增加了以下到htaccess文件:

So, I've added the following to an htaccess file:

XSendFile上 XSendFilePath /家庭/熟食店/中心 XSendFileAllowAbove在

XSendFile on XSendFilePath /home/deli/central XSendFileAllowAbove On

(从脚本到中央文件目录的相对路径../../熟食店/中心)

(The relative path from the script to the central file directory is ../../deli/central)

如果我这些行添加到htaccess的,并把它放在public_html目录(同一目录下测试脚本),当我再运行测试脚本,我得到一个500错误。快看看错误日志说明:

If I add these lines to the htaccess, and put it in the public_html directory (same directory as the test script), when I then run the test script I get a 500 error. Quick look at the error logs shows:

/home/north/public_html/.htaccess:XSendFilePath此处不允许

/home/north/public_html/.htaccess: XSendFilePath not allowed here

可能有人开导我,要什么我可能是做错了?

Could anyone enlighten me as to anything I might be doing wrong?

ps的 - 我刚看完,这是更有效地做到这一点在Apache的配置,因此服务器是不是有爬行通过并加载所有的htaccess文件。不知道这是真的还是假的。

ps - I just read that it is much more efficient to do it in the apache config, so the server is not having to crawl through and load all htaccess files. Don't know if this is true or not.

帮助是非常AP preciated,这是一个有点该项目的搅局者:)

Help is very much appreciated, this is a bit of a showstopper on the project :)

PS我忘了提 - 如果我把在一条直线力下载到脚本,使用相同的$文件路径,文件下载就好了。这样的路径似乎是正确的。

ps I forgot to mention - if I put in a straight force-download into the script, using the same $file path, the file downloads just fine. So the path would seem to be correct.

推荐答案

我希望这将帮助别人......

I hope this will help someone...

我是有这样的问题:无论何时无论 - > 0字节

I was having this kind of problem: whenever and whatever -> 0 bytes

我解决这个移动

XSendFile On
XSendFilePath /var/1000italy/data/offline

从虚拟主机部分

from the virtualHost section

<VirtualHost *:80>

    DocumentRoot "/var/{{ app_name }}/web"
    ServerName {{ app_name }}.dev

    # here was the problem
    XSendFile On
    XSendFilePath /var/1000italy/data/offline

    <Directory "/var/{{ app_name }}/web">
        allow from all
        Options -Indexes
        AllowOverride All
    </Directory>

    ErrorLog /var/log/apache2/{{ app_name }}_error.log
    CustomLog /var/log/apache2/{{ app_name }}_access.log combined

</VirtualHost>

到目录节

<VirtualHost *:80>

    DocumentRoot "/var/{{ app_name }}/web"
    ServerName {{ app_name }}.dev

    <Directory "/var/{{ app_name }}/web">
        allow from all
        Options -Indexes
        AllowOverride All

        # HERE EVERYTHING WORKS FINE
        XSendFile On
        XSendFilePath /var/1000italy/data/offline
    </Directory>

    ErrorLog /var/log/apache2/{{ app_name }}_error.log
    CustomLog /var/log/apache2/{{ app_name }}_access.log combined

</VirtualHost>

这篇关于XSendfile不工作 - PHP,Apache的,交友的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆