javascript - Load video file to html5 player with php -


i have little problem video. created service user going see on every page, 1 video our application.

situation

when click on video icon, pop-up going open - action:

 var getvideomodal = function (video) {   var path = '/application/files/help/tutorial_videos/'+video;   $('div#modal-video').modal('show');   $("#modal-video").draggable({     handle: ".modal-header"   });   $('h3#modal-header-video').html(video);   console.log(path);   $("#video-help").find("#videopath").attr("src", path);   centermodal(); } 

when pop-up opened, there (in popup body) <video> html5 element

  <video id="video-help" width="530" controls>     <source id="videopath" src="" type="video/mp4">   </video> 

pop-up si working, video not.

problem:

i have problem because have video stored in "/application/help/videos". path forbidden , can't call url in browser. how can load videos restricted area php (which have access, through file system) video player

i need like:

  <video id="video-help" width="530" controls>         <source id="videopath" src="whatever.php?video=loaded.mp4" type="video/mp4">   </video>     

is possible?

you can go php send video data restricted folder access. open, read file , send data.

you can make working if user move player timeline sending data range. code below :

    $my_video_basename = //filter have trust filename      $file = "/application/help/videos" . $my_video_basename;      if(!file_exists($file)) return;       $fp = @fopen($file, 'rb');           $size   = filesize($file); // file size      $length = $size;           // content length     $start  = 0;               // start byte     $end    = $size - 1;       // end byte       header('content-type: video/mp4');     header("accept-ranges: 0-$length");     header("accept-ranges: bytes");      if (isset($_server['http_range'])) {         $c_start = $start;                       $c_end   = $end;                         list(, $range) = explode('=', $_server['http_range'], 2);         if (strpos($range, ',') !== false) {             header('http/1.1 416 requested range not satisfiable');             header("content-range: bytes $start-$end/$size");             exit;               }                       if ($range == '-') {                         $c_start = $size - substr($range, 1);         }else{                      $range  = explode('-', $range);              $c_start = $range[0];                        $c_end   = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;         }         $c_end = ($c_end > $end) ? $end : $c_end;         if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {              header('http/1.1 416 requested range not satisfiable');             header("content-range: bytes $start-$end/$size");             exit;               }         $start  = $c_start;                      $end    = $c_end;                        $length = $end - $start + 1;             fseek($fp, $start);                      header('http/1.1 206 partial content');     }                       header("content-range: bytes $start-$end/$size");     header("content-length: ".$length);     $buffer = 1024 * 8;     while(!feof($fp) && ($p = ftell($fp)) <= $end) {          if ($p + $buffer > $end) {                   $buffer = $end - $p + 1;                 }                       set_time_limit(0);                       echo fread($fp, $buffer);                ob_flush();         }     fclose($fp);            exit(); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -