简体   繁体   中英

Video streaming using PHP?

Alrighty so since the Class I was looking at isn't for remote files but instead is for local files.. I decided to do some searching and found this cURL code that seems promising to actually play REMOTE URI's

    $head = array_change_key_case(get_headers($path, TRUE));
    $filesize = $head['content-length'];

    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_URL, $path); 
    curl_setopt($curl, CURLOPT_RANGE, max (0, $filesize - 128) . '-' . max (0, $filesize - 1));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $content = curl_exec($curl);

    header("Content-Type: video/mp4");
    header("Cache-Control: max-age=2592000, public");
    header("Expires: ".gmdate('D, d M Y H:i:s', time()+2592000) . ' GMT');
    header("Last-Modified: ".gmdate('D, d M Y H:i:s', @filemtime($this->path)) . ' GMT' );
    echo $content;

This is what I got so far, I copied most of the headers from the class from before and I also am now using cURL for this.. I do get the same result which is just a black player, playing.

And here is the response I get when I echo $content

HTTP/1.1 206 Partial Content
Server: nginx/1.4.6 (Ubuntu)
Date: Fri, 06 May 2016 23:56:18 GMT
Content-Type: video/mp4
Content-Length: 128
Last-Modified: Fri, 06 May 2016 19:07:20 GMT
Connection: keep-alive
ETag: "572ceb68-75445cb"
Expires: Fri, 13 May 2016 23:56:18 GMT
Cache-Control: max-age=604800
Cache-Control: public
Content-Range: bytes 122963275-122963402/122963403

If it is a remote URL, check your server allows fopen to open remote files. allow_url_fopen needs to be enable in your php.ini

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM