开发者

Xsendfile File Not Found

开发者 https://www.devze.com 2023-04-06 02:17 出处:网络
I am using mod_xsendfile on Dreamhost to download large zip files (50mb+) I have mod_xsendfile enabled, and \"XSendFile on\" in my .htaccess.

I am using mod_xsendfile on Dreamhost to download large zip files (50mb+)

I have mod_xsendfile enabled, and "XSendFile on" in my .htaccess.

When I give the

header('X-Sendfile: "'.$fullPath.'"');

command, using the full path to a file that does exist on the server, I am getting a webpage not found error.

readfile() finds the file just fine and serves it, but the .zip files have gotten too large for php to handle.

Any help you could provide would be appreciated开发者_开发问答!


There is actually an apache/xsendfile configuration value for this.

In your host configuration, you can simply add:

XSendFilePath /tmp

Where /tmp is wherever you want xsendfile to be able to access. It's a whitelist, and I believe you can add more than one.

For example:

<Directory /var/www/mysite/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    XSendFile On
    XSendFilePath /tmp
</Directory>


I had the same problem and was able to solve it, so possibly this solution will work for you.

First thing to do is to check your Apache error logs (for me, located in /etc/httpd/logs). This is what I found in mine:

[Wed Sep 05 14:29:02 2012] [error] [client ?.?.?.?] (20023)The given path was above the root path: xsendfile: unable to find file: /path/to/file

The problem was, the file I was looking to serve was located above the DocumentRoot (for me, /var/www/html) as defined in httpd.conf.

My solution was to create a symlink in the DocumentRoot directory that pointed to the directory which contained the file I want to serve. I used the following command:

ln -s /path/to/file_dir /path/to/doc_root/file_dir

Then all I had to do was have PHP point xSendFile to the symlink:

header("X-SendFile: /path/to/doc_root/file_dir/file_name.ext");


I have finally found the easiest solution for this:

header('X-Sendfile: '.realpath(dirname(__FILE__)).'/'.$the_rest_of_path);   

This way it's working perfectly for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消