Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Pobieranie i wznawianie pliku z innego serwera.
diabel
post
Post #1





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 12.12.2011

Ostrzeżenie: (0%)
-----


Witam,
mam problem dość błachy dla jednych dla mnie okazał sie za trudny (badz zmeczenie juz daje o sobie znac); chodzi mi o pobieranie pliku z innego serwera i wysyłanie go jednoczesnie. To juz rozwiazalem w banalny sposob problem pojawia sie w momencie kiedy zatrzyjmuje pobieranie, bo Babcia Stasia chce wysłać e-maila a ze internet jest na chomiki to wypadalo by zwolnic troche łącza.
  1. <?php
  2. 'http' => array(
  3. 'method' => 'GET',
  4. 'follow_location' => 1
  5. )
  6. ));
  7.  
  8. if (($fp = @fopen($link->url, 'r', FALSE, $context)) !== FALSE)
  9. {
  10. $range = 0;
  11. $size = $link->filesize;
  12. header( 'Content-Disposition: attachment; filename="' . $link->filename . '"' );
  13. header( 'Accept-Ranges: bytes' );
  14.  
  15. if(isset($_SERVER['HTTP_RANGE']))
  16. {
  17. list($a, $range) = explode("=",$_SERVER['HTTP_RANGE'],2);
  18. list($range) = explode(',', $range, 2);
  19. list($range, $range_end) = explode('-', $range);
  20.  
  21. if (! $range_end)
  22. $range_end=$size-1;
  23. else
  24. $range_end=intval($range_end);
  25.  
  26. $new_length = $range_end-$range+1;
  27. header("HTTP/1.1 206 Partial Content");
  28. header("Content-Length: $new_length");
  29. header("Content-Range: bytes $range-$range_end/$size");
  30. }
  31. else
  32. {
  33. $new_length=$size;
  34. header("Content-Length: ".$size);
  35. }
  36. header( 'Content-type: application/force-download' );
  37. fseek($fp, $range);
  38. while (! feof($fp))
  39. {
  40. echo fread($fp, 1024); // nie bedziemy szalec
  41. flush();
  42. }
  43. fclose($fp);
  44. exit();
  45. }
  46. return FALSE;
  47. ?>

Tak czy siak fseek nie działa z http[s], czy znacie jakies alternatywy?

Pozdrawiam.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 08:16