Cześć,

nie wiem czy wyrażam się poprawnie, ale trudno... chodzi mi o to czy jest możliwy streaming pobieranego pliku? Chodzi o to, że pobieram jakiś plik z serwera i w tym pośredniczy inny serwer (chodzi o to, że plik nie jest na niego bezpośrednio zapisywany, a tylko pośredniczy w połączeniu)? Znalazłem na php.net funkcję i zaciekawiła minie... bo wydaje mi się, że tak działa, proszę o zerknięcie na to i odpowiedź:

  1. <?php
  2.  
  3. function dl_file_resumable($file, $is_resume=TRUE)
  4. {
  5. //First, see if the file exists
  6. if (!is_file($file))
  7. {
  8. die("<b>404 File not found!</b>");
  9. }
  10.  
  11. //Gather relevent info about file
  12. $size = filesize($file);
  13. $fileinfo = pathinfo($file);
  14.  
  15. //workaround for IE filename bug with multiple periods / multiple dots in filename
  16. //that adds square brackets to filename - eg. setup.abc.exe becomes setup[1].abc.exe
  17. $filename = (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) ?
  18. preg_replace('/\./', '%2e', $fileinfo['basename'], substr_count($fileinfo['basename'], '.') - 1) :
  19. $fileinfo['basename'];
  20.  
  21. $file_extension = strtolower($path_info['extension']);
  22.  
  23. //This will set the Content-Type to the appropriate setting for the file
  24. switch($file_extension)
  25. {
  26. case 'exe': $ctype='application/octet-stream'; break;
  27. case 'zip': $ctype='application/zip'; break;
  28. case 'mp3': $ctype='audio/mpeg'; break;
  29. case 'mpg': $ctype='video/mpeg'; break;
  30. case 'avi': $ctype='video/x-msvideo'; break;
  31. default: $ctype='application/force-download';
  32. }
  33.  
  34. //check if http_range is sent by browser (or download manager)
  35. if($is_resume && isset($_SERVER['HTTP_RANGE']))
  36. {
  37. list($size_unit, $range_orig) = explode('=', $_SERVER['HTTP_RANGE'], 2);
  38.  
  39. if ($size_unit == 'bytes')
  40. {
  41. //multiple ranges could be specified at the same time, but for simplicity only serve the first range
  42. //http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt
  43. list($range, $extra_ranges) = explode(',', $range_orig, 2);
  44. }
  45. else
  46. {
  47. $range = '';
  48. }
  49. }
  50. else
  51. {
  52. $range = '';
  53. }
  54.  
  55. //figure out download piece from range (if set)
  56. list($seek_start, $seek_end) = explode('-', $range, 2);
  57.  
  58. //set start and end based on range (if set), else set defaults
  59. //also check for invalid ranges.
  60. $seek_end = (empty($seek_end)) ? ($size - 1) : min(abs(intval($seek_end)),($size - 1));
  61. $seek_start = (empty($seek_start) || $seek_end < abs(intval($seek_start))) ? 0 : max(abs(intval($seek_start)),0);
  62.  
  63. //add headers if resumable
  64. if ($is_resume)
  65. {
  66. //Only send partial content header if downloading a piece of the file (IE workaround)
  67. if ($seek_start > 0 || $seek_end < ($size - 1))
  68. {
  69. header('HTTP/1.1 206 Partial Content');
  70. }
  71.  
  72. header('Accept-Ranges: bytes');
  73. header('Content-Range: bytes '.$seek_start.'-'.$seek_end.'/'.$size);
  74. }
  75.  
  76. //headers for IE Bugs (is this necessary?)
  77. //header("Cache-Control: cache, must-revalidate");
  78. //header("Pragma: public");
  79.  
  80. header('Content-Type: ' . $ctype);
  81. header('Content-Disposition: attachment; filename="' . $filename . '"');
  82. header('Content-Length: '.($seek_end - $seek_start + 1));
  83.  
  84. //open the file
  85. $fp = fopen($file, 'rb');
  86. //seek to start of missing part
  87. fseek($fp, $seek_start);
  88.  
  89. //start buffered download
  90. while(!feof($fp))
  91. {
  92. //reset time limit for big files
  93. print(fread($fp, 1024*8));
  94. flush();
  95. }
  96.  
  97. fclose($fp);
  98. }
  99.  
  100. ?>


Dodatkowo czy jest możliwość zrobienia czegoś takiego w curl?