SHARE
TWEET

Untitled

a guest Nov 8th, 2011 116 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // Report all PHP errors
  3. error_reporting(E_ALL);
  4. ini_set('display_errors', '1');
  5.  
  6. // Open rar archive
  7. $rar_file = rar_open('test.rar');
  8. if ($rar_file === false)
  9.     die("Failed to open Rar archive");
  10.  
  11. // Get video file in archive
  12. $entry = rar_entry_get($rar_file, 'video.mkv');
  13. if ($entry === false)
  14.     die("Failed to find such entry");
  15.  
  16.  
  17. header('Content-Type: application/octet-stream');
  18. header('Content-Disposition: inline; filename="video.mkv"');
  19.  
  20. // Seek
  21. $seek_start = 0;
  22. $seek_end = -1;
  23. $fs = $entry->getPackedSize();
  24.  
  25. if (isset($_SERVER['HTTP_RANGE']) || isset($HTTP_SERVER_VARS['HTTP_RANGE'])) {
  26.  
  27.     $seek_range = isset($HTTP_SERVER_VARS['HTTP_RANGE']) ? substr($HTTP_SERVER_VARS['HTTP_RANGE'], strlen('bytes=')) : substr($_SERVER['HTTP_RANGE'], strlen('bytes='));
  28.     $range = explode('-', $seek_range);
  29.  
  30.     if ($range[0] > 0) {
  31.         $seek_start = intval($range[0]);
  32.     }
  33.  
  34.     $seek_end = ($range[1] > 0) ? intval($range[1]) : -1;
  35.  
  36.  
  37.     header('HTTP/1.0 206 Partial Content');
  38.     header('Status: 206 Partial Content');
  39.     header('Accept-Ranges: bytes');
  40.     header("Content-Range: bytes $seek_start-$seek_end/" . $fs);
  41. }
  42.  
  43. if ($seek_end < $seek_start) {
  44.     $seek_end = $fs - 1;
  45. }
  46. $cl = $seek_end - $seek_start + 1;
  47.  
  48. header('Content-Length: ' . $cl);
  49. ob_flush();
  50.  
  51.  
  52. // Get file stream
  53. $stream = $entry->getStream();
  54. rar_close($rar_file); //stream is independent from file
  55.  
  56. if ($stream === false)
  57.     die("Failed to obtain stream.");
  58.  
  59. fseek($stream, $seek_start);
  60. // Start stream
  61. while (!feof($stream)) {
  62.     set_time_limit(0);
  63.     print(fread($stream, 8192));
  64.     flush();
  65.     ob_flush();
  66. }
  67.  
  68. fclose($stream);
  69. ?>
  70.  
  71.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top