Advertisement
Guest User

Untitled

a guest
Feb 20th, 2012
3,480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2. require_once 'http.php';
  3.  
  4. // fill this with actual values
  5. $url = 'http://www.google.ru/images/srpr/logo3w.png';
  6. $file_size = 7007;
  7. $name = 'test.bin';
  8.  
  9. $server_http_range = isset($_SERVER['HTTP_RANGE']) ? $_SERVER['HTTP_RANGE'] : false;
  10.  
  11. $request_ranges = array();
  12.  
  13. if ($server_http_range) {
  14.   $range_list = HTTP\parse_range_request($file_size, $server_http_range);
  15.  
  16.   if ($range_list === false) {
  17.     exit();
  18.   }
  19.  
  20.   if (empty($range_list)) {
  21.     header('Status: 416 Requested range not satisfiable');
  22.     exit();
  23.   }
  24.  
  25.   foreach ($range_list as $range) {
  26.     $request_ranges[] = $range->get_first_pos() . '-' . $range->get_last_pos();
  27.   }
  28.  
  29.   header('Status: 206 Partial Content');
  30. } else {
  31.   $request_ranges[] = "0-" . ($file_size - 1);
  32.  
  33.   header('Status: 200 Ok');
  34.   header('Content-Length: ' . $file_size);
  35. }
  36.  
  37. header('Content-Type: application/octet-stream');
  38. header('Accept-Ranges: bytes');
  39. header('Content-Disposition: attachment; filename="' . $name . '";');
  40.  
  41. $ch = curl_init();
  42. curl_setopt($ch, CURLOPT_VERBOSE, 1);
  43. curl_setopt($ch, CURLOPT_URL, $url);
  44. curl_setopt($ch, CURLOPT_RANGE, implode(',', $request_ranges));
  45. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
  46. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  47. curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  48. $result = curl_exec($ch);
  49.  
  50. curl_close($ch);
  51.  
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement