-
-
Save kicktv/747d04d1069298879ff9783b69751595 to your computer and use it in GitHub Desktop.
PHP streaming proxy with support for Range requests (perfect for proxying video files with progressive download MP4 streaming)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| error_reporting(0); | |
| set_time_limit(0); | |
| ob_end_clean(); | |
| $url = $_GET['url']; | |
| if(isset($_SERVER['HTTP_RANGE'])) { | |
| stream_context_set_default([ | |
| 'http' => [ | |
| 'header' => "Range: " . $_SERVER['HTTP_RANGE'] | |
| ] | |
| ]); | |
| } | |
| $headers = get_headers($url, 1); | |
| header($headers[0]); | |
| if(isset($headers['Content-Type'])) { header('Content-Type: ' . $headers['Content-Type']); } | |
| if(isset($headers['Content-Length'])) { header('Content-Length: ' . $headers['Content-Length']); } | |
| if(isset($headers['Accept-Ranges'])) { header('Accept-Ranges: ' . $headers['Accept-Ranges']); } | |
| if(isset($headers['Content-Range'])) { header('Content-Range: ' . $headers['Content-Range']); } | |
| if($_SERVER['REQUEST_METHOD'] == 'HEAD') { exit; } | |
| $fp = fopen($url, 'rb'); | |
| while(!feof($fp)) { | |
| echo fread($fp, 1024 * 256); flush(); | |
| } | |
| fclose($fp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment