Okay - I have a WAMP-setup with mod_xsendfile installed - it is loaded in the modules-folder in the Apache-folder under WAMP, and the appropriate lines has been added to httpd.conf, and the module shows up in the list when I check the available modules via the WAMP-icon.

However, I can't for the life of me get it to actually work. I use it in a webpage I'm developing to send thumbnails / images / files to a gallery, and this works just fine on a MAMP-server where I did the first development. I'm using PHP for the backend, and am posting the relevant code here - if you need anything else, I would be happy to provide it.

First: httpd.conf

LoadModule xsendfile_module modules/mod_xsendfile.so
<IfModule mod_xsendfile.so>
  <Files *.php>
    XSendFile On

Not entirely sure about that bit, but I've also tried this, without success:

# Enable mod_xsendfile
#permitted values on/off
XSendFile on
# XSendFilePath allow you to add additional paths to some
# kind of white list. All files within these paths are
#allowed to get served through mod_xsendfile
XSendFilePath "c:\wamp\www\uploadr\users\"

Here's the PHP-file which is returning files via X-Sendfile:

if (!session_id()) { session_start(); };

$username = (($isloggedin && isset($_GET['user'])) ? $_GET['user'].'/' : ((!$isloggedin) ? 'public/' : $username));
if (!empty($_SERVER['QUERY_STRING']) && $username != 'public/') {
    $potential_public_file = explode('__',explode('=',$_SERVER['QUERY_STRING'])[1])[0];
    for ($i = 0; $i < count($user_array); $i++) {
        $exploded_user_array = explode('//',$user_array[$i]);
        if (($potential_public_file == trim($exploded_user_array[0]))) {
            $username = 'public/';
    if ($debug == true) {
        logThis('showfile_processing','Username is set to '.$username.''."\r\n",FILE_APPEND);
    if (isset($_GET['imgfile'])) {
        header('Content-type: image/jpeg');
        if (isset($_GET['thumbs'])) {
            header('X-Sendfile: '.$_SERVER['DOCUMENT_ROOT'].'/'.$userpath.$username.'pictures/thumbs/'.$_GET['imgfile']);
        } else {
            header('X-Sendfile: '.$_SERVER['DOCUMENT_ROOT'].'/'.$userpath.$username.'pictures/'.$_GET['imgfile'].'');
    } elseif (isset($_GET['docfile'])) {
        header('Content-Disposition: attachment; filename='.$_GET['docfile'].'');
        header('X-Sendfile: '.$_SERVER['DOCUMENT_ROOT'].'/'.$userpath.$username.'documents/'.$_GET['docfile'].'');
    } elseif (isset($_GET['vidfile'])) {
        if (isset($_GET['thumbs'])) {
            if ($debug == true) {
                logThis('showfile_processing','Thumbs loaded '.$_GET['vidfile']."\r\n",FILE_APPEND);    
            header('Content-type: image/jpeg');
            header('X-Sendfile: '.$_SERVER['DOCUMENT_ROOT'].'/'.$userpath.$username.'video/thumbs/'.$_GET['vidfile']);
        } else {
            if ($debug == true) {
                logThis('showfile_processing','Video returned '.$_GET['vidfile']."\r\n",FILE_APPEND);
            header('Content-Disposition: attachment; filename='.$_GET['vidfile'].'');
            header('X-Sendfile: '.$_SERVER['DOCUMENT_ROOT'].'/'.$userpath.$username.'video/'.$_GET['vidfile'].'');

And I'm calling those files from the gallery.php-file, something like this: showfile.php?imgfile=<name_of_file> - it basically reads through a directory, and pulls the files via X-Sendfile to mask the placement of the files on the server from the user.

(This question was first asked on Server Fault, but they suggested I move it here)

UPDATE I tried going directly to the showfile.php, and loading an image there, and I get a new error: The image “http://uploadr.loc/showfile?imgfile=05_196132738.jpg” cannot be displayed because it contains errors. as an alt-text. Regardless of which image I'm trying to load, it returns this error. Tested the exact same pictures on my MAMP-setup, they work just fine. So I'm wondering if there is a something specific either with the Windows setup, or the path to the file that creates the problem?


And, wow, did it take me a long time to find this out, but I found the answer here: https://stackoverflow.com/questions/7133819/x-sendfile-on-apache2-php-serving-0b-file-no-errors-though

I had to set the XSendFilePath to C:/ - and it magically works. That's Windows for you...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.