Using X-Sendfile with Apache/Php

PHP File Serving using X-Sendfile

I finally solved this problem with the use of X-Sendfile apache module

<?php
if (file_exists($file))
{
// send the right headers
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Content-type: ' . $fmime);
header('Content-Length: ' . filesize($file));

// Make sure you have X-Sendfile module installed on your server
// To download this module, go to https://www.apachelounge.com/download/
header('X-Sendfile: ' . $file);
exit;
}
else
{
die('File loading failed.');
}

X-Sendfile works for all folder and not just XSendFilePath

Try with the XSendFilePath directive

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.

PHP - How to find out if X-Sendfile is available and installed?

The APACHE module mod_xsendfile processes the X-Sendfile headers

To check if the APACHE module mod_xsendfile is available and installed on the server, you could use apache_get_modules() function.

You cannot just set the header and check if the module is installed or not.

PHP can't display image using X-SendFile and jpeg headers

The above code did work, it was x-sendfile which was not configured properly in apache



Related Topics



Leave a reply



Submit