Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xsendfile File Not Found

Tags:

file

php

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!

like image 502
Joe Cole Avatar asked Oct 09 '22 23:10

Joe Cole


2 Answers

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>
like image 82
jhaagsma Avatar answered Oct 14 '22 03:10

jhaagsma


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");
like image 33
Wavy Davy Avatar answered Oct 14 '22 01:10

Wavy Davy