I am creating a PHP access handler file which will server images and videos to users based on if they have authorisation.
I need to block direct access to the files to ensure that the user auth cannot be bypassed, what's the most efficient way to serve images and video without chewing up too much memory?
I tried using X-SendFile below but this only allows you to download files and not display them, I was hoping it would be possible to automatically get the file headers (they will more then likely be .mp4 videos and .jpgs).
<?PHP
$file = $_GET['f'];
$filepath = $_GET['fp'];
//if auth success (security will be put in here)
if(TRUE == TRUE){
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment;filename='.$file);
header('X-Sendfile: '.$filepath);
}else{ echo "Unauthorized access"; exit(); }
?>
**UPDATE**
Trying to get it working but getting errors.
//Get media file content type
$finfo = finfo_open(FILEINFO_MIME_TYPE);
//Display correct headers for media file
header("Content-type: ".finfo_file($finfo, $filepath));
//echo "here".finfo_file($finfo, $filepath);
finfo_close($finfo);
header('Content-length: '.filesize($filepath));
header('Content-Disposition: inline; filename="'.$file.'"');
header('X-Sendfile: ' . $filepath );