Joe Cole Joe Cole - 1 year ago 132
PHP Question

Xsendfile File Not Found

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!

Answer Source

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");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download