fork(1) download
  1. <?php
  2. // disable zlib so that progress bar of player shows up correctly
  3. if(ini_get('zlib.output_compression')) {
  4. ini_set('zlib.output_compression', 'Off');
  5. }
  6.  
  7. $folder = '.';
  8. $filename = 'video.mp4';
  9. $path = $folder.'/'.$filename;
  10.  
  11. // from: http://l...content-available-to-author-only...n.net/post/stream-videos-php/
  12. if (file_exists($path)) {
  13. // Clears the cache and prevent unwanted output
  14.  
  15. $mime = "video/mp4"; // The MIME type of the file, this should be replaced with your own.
  16. $size = filesize($path); // The size of the file
  17.  
  18. // Send the content type header
  19. header('Content-type: ' . $mime);
  20.  
  21. // Check if it's a HTTP range request
  22. if(isset($_SERVER['HTTP_RANGE'])){
  23. // Parse the range header to get the byte offset
  24. $ranges = array_map(
  25. 'intval', // Parse the parts into integer
  26. '-', // The range separator
  27. substr($_SERVER['HTTP_RANGE'], 6) // Skip the `bytes=` part of the header
  28. )
  29. );
  30.  
  31. // If the last range param is empty, it means the EOF (End of File)
  32. if(!$ranges[1]){
  33. $ranges[1] = $size - 1;
  34. }
  35.  
  36. // Send the appropriate headers
  37. header('HTTP/1.1 206 Partial Content');
  38. header('Accept-Ranges: bytes');
  39. header('Content-Length: ' . ($ranges[1] - $ranges[0])); // The size of the range
  40.  
  41. // Send the ranges we offered
  42. 'Content-Range: bytes %d-%d/%d', // The header format
  43. $ranges[0], // The start range
  44. $ranges[1], // The end range
  45. $size // Total size of the file
  46. )
  47. );
  48.  
  49. // It's time to output the file
  50. $f = fopen($path, 'rb'); // Open the file in binary mode
  51. $chunkSize = 8192; // The size of each chunk to output
  52.  
  53. // Seek to the requested start range
  54. fseek($f, $ranges[0]);
  55.  
  56. // Start outputting the data
  57. while(true){
  58. // Check if we have outputted all the data requested
  59. if(ftell($f) >= $ranges[1]){
  60. break;
  61. }
  62.  
  63. // Output the data
  64. echo fread($f, $chunkSize);
  65.  
  66. // Flush the buffer immediately
  67. flush();
  68. }
  69. }
  70. else {
  71. // It's not a range request, output the file anyway
  72. header('Content-Length: ' . $size);
  73.  
  74. // Read the file
  75. @readfile($path);
  76.  
  77. // and flush the buffer
  78. flush();
  79. }
  80.  
  81. }
  82. die();
  83.  
  84. ?>
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Standard output is empty