html - PHP File Serving using X-Sendfile -


i'm building website file serving script. script allows website deliver pdf, mp3 , mp4 files. pdf , mp3 files working. clicking on play video, i'im expecting video file play it's not. video controls have been disabled , unable play.

files.php

<?php error_reporting(e_all);  $fid = $_get['fid']; $ftype = $_get['ftype']; // e.g. audios, videos, ebooks $fcat = isset($_get['cat']) ? $_get['cat'] . '/' : ''; // e.g. lessons, more $fext = ''; $fmime = '';  switch ($ftype) {     case 'ebooks':         $fext = '.pdf';         $fmime = 'application/pdf';         break;     case 'audios':         $fext = '.mp3';         $fmime = 'audio/mp3';         break;     default:         $fext = '.mp4';         $fmime = 'video/mp4';         break; }  // example: audios/lessons/audio1.mp3 $file = $ftype . '/' . $fcat . str_replace('s', '', $ftype) . $fid . $fext;  if (file_exists($file)) {        // open file binary mode     $fp = fopen($file, 'rb');      // send 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));      // dump file stop program     fpassthru($fp);     exit; } else {     die('file loading failed.'); } 

video.php

<video src="/products/files.php?fid=1&ftype=videos&cat=lessons" autoplay controls></video> 

alternatively, address bar

mydomain.com/products/files.php?fid=1&ftype=videos&cat=lessons 

could else find out did wrong? in advance.

i solved problem use of x-sendfile apache module

<?php if (file_exists($file)) {     // send 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 have x-sendfile module installed on server     // download module, go https://www.apachelounge.com/download/     header('x-sendfile: ' . $file);      // dump file stop program     fpassthru($fp);     exit; } else {     die('file loading failed.'); } 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -