Using php to output an mp4 video

前端 未结 4 1431
感动是毒
感动是毒 2020-11-27 13:33

Ok basically I have a project that requires that videos are hidden from the users while still able to see them (by using php). here\'s what i got so far:

The video.

4条回答
  •  -上瘾入骨i
    2020-11-27 14:20

    Yes, its easy to do. No need to set those headers manually. Let the server do it automatically.

    Heres a working script -

    ob_start();
    
    if( isset($_SERVER['HTTP_RANGE']) )
    
    $opts['http']['header']="Range: ".$_SERVER['HTTP_RANGE'];
    
    $opts['http']['method']= "HEAD";
    
    $conh=stream_context_create($opts);
    
    $opts['http']['method']= "GET";
    
    $cong= stream_context_create($opts);
    
    $out[]= file_get_contents($real_file_location_path_or_url,false,$conh);
    
    $out[]= $http_response_header;
    
    ob_end_clean();
    
    array_map("header",$http_response_header);
    
    readfile($real_file_location_path_or_url,false,$cong);
    

提交回复
热议问题