Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]header i wznawianie pobierania pliku
webmaestro
post
Post #1





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 25.12.2009

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


Moglby ktos podpowiedziec jak zrobic skrypt pobierania pliku przez wyslanie naglowka header z mozliwoscia wznowienia pobrania pliku?
Plik czytam readfile().
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
erix
post
Post #2





Grupa: Moderatorzy
Postów: 15 467
Pomógł: 1451
Dołączył: 25.04.2005
Skąd: Szczebrzeszyn/Rzeszów




Czy ogniem możesz zgasić wodę?

Nie, nie da się; cURL jest do czego innego - rusz swoje szanowne cztery litery i poszukaj, jak wygląda, jak jest skonstruowany ten nagłówek, o którym masz już wspomniane n-ty raz.

Gotowca nie dostaniesz, na to nie licz.
Go to the top of the page
+Quote Post
webmaestro
post
Post #3





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 25.12.2009

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


Cytat(erix @ 30.12.2009, 15:53:35 ) *
Czy ogniem możesz zgasić wodę?

Nie, nie da się; cURL jest do czego innego - rusz swoje szanowne cztery litery i poszukaj, jak wygląda, jak jest skonstruowany ten nagłówek, o którym masz już wspomniane n-ty raz.

Gotowca nie dostaniesz, na to nie licz.

A no sie myslisz bo curlem sie da zrobic tez...
Poczytaj o: CURLOPT_RANGE


  1. <?
  2. $file = "sa.rar";
  3. $filesize = filesize($file);
  4. $fileName= "sa.rar";
  5. $offset = 0;
  6. $length = $filesize;
  7.  
  8. if ( isset($_SERVER['HTTP_RANGE']) ) {
  9. // if the HTTP_RANGE header is set we're dealing with partial content
  10.  
  11. $partialContent = true;
  12.  
  13. // find the requested range
  14. // this might be too simplistic, apparently the client can request
  15. // multiple ranges, which can become pretty complex, so ignore it for now
  16. preg_match('/bytes=(\d+)-(\d+)?/', $_SERVER['HTTP_RANGE'], $matches);
  17.  
  18. $offset = intval($matches[1]);
  19. $length = intval($matches[2]) - $offset;
  20. } else {
  21. $partialContent = false;
  22. }
  23.  
  24. $file = fopen($file, 'r');
  25.  
  26. // seek to the requested offset, this is 0 if it's not a partial content request
  27. fseek($file, $offset);
  28.  
  29. $data = fread($file, $length);
  30.  
  31. fclose($file);
  32.  
  33. if ( $partialContent ) {
  34. // output the right headers for partial content
  35.  
  36. header('HTTP/1.1 206 Partial Content');
  37.  
  38. header('Content-Range: bytes ' . $offset . '-' . ($offset + $length) . '/' . $filesize);
  39. }
  40.  
  41. // output the regular HTTP headers
  42. header("Content-Type: application/octet-stream");
  43. header('Content-Length: ' . $filesize);
  44. header('Content-Disposition: attachment; filename="' . $fileName . '"');
  45. header('Accept-Ranges: bytes');
  46.  
  47. // don't forget to send the data too
  48. print($data);


A w tym kodzie co moze byc zle ze nie da sie zapauzowac/wznowic pobierania?(IMG:style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 5.10.2025 - 03:34