Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> pobieranie plików
koneser69
post
Post #1





Grupa: Zarejestrowani
Postów: 45
Pomógł: 0
Dołączył: 18.11.2008

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


witam

Za pomocą poniższego kodu realizuje pobieranie plików. Problem jest w tym, że podczas pobierania nie można wejść na żadną stronę ponieważ cały dostępny transfer jest zapchany. Czy istnieje jakiś sposób na obejście tego problemu questionmark.gif

  1. header('Content-Description: File Transfer');
  2. header('Content-Type: application/octet-stream');
  3. header('Content-Disposition: attachment; filename='.$fileName);
  4. header('Content-Transfer-Encoding: binary');
  5. header('Expires: 0');
  6. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  7. header('Pragma: public');
  8. header('Content-Length: ' . filesize($dir.$lock));
  9. readfile($dir.$lock);
  10.  
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
tabbi
post
Post #2





Grupa: Zarejestrowani
Postów: 150
Pomógł: 3
Dołączył: 30.10.2010

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


Obejście metody readfile

  1. $fp = fopen($fileLink, 'r') or die ("404");
  2. header("Pragma: no-cache");
  3. header("Content-Type: application/x-unknown");
  4. header("Expires: 0");
  5. header("Content-Length: ".$file['size']);
  6. header("Content-Transfer-Encoding: binary");
  7. @header('Content-Disposition: attachment; filename="'.$file['filename'].'"');
  8. if(!fp) exit; // if $fp is not a valid stream resource, exit
  9. fseek($fp,$byte_from);
  10. while(!feof($fp)){
  11. //reset time limit for big files
  12. print(fread($fp,1024*8));
  13. flush();
  14. }
  15. fpassthru($fp);
  16. fclose($fp);
Go to the top of the page
+Quote Post
koneser69
post
Post #3





Grupa: Zarejestrowani
Postów: 45
Pomógł: 0
Dołączył: 18.11.2008

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


Witam

@tabbi ten kod zapchał mi transfer jeszcze bardziej. Jak plik się pobierał nie mogłem nawet połączyć się po ssh z serwerem. A może problem leży w php.ini. Albo w jakiejś opcji konfiguracyjnej serwera questionmark.gif
Go to the top of the page
+Quote Post
kiler129
post
Post #4





Grupa: Zarejestrowani
Postów: 566
Pomógł: 35
Dołączył: 21.06.2006

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


Nie wiem o jakim zapychaniu łącza mówisz (a może o tym, że nie ustalasz sobie limitu prędkości?) ale jeśli chcesz ograniczyć prędkość wysyłania danych do klienta to jest na to skuteczny sposób:

  1. <?php
  2.  
  3. $fp = fopen($fileLink, 'r') or die ("404");
  4. header("Pragma: no-cache");
  5. header("Content-Type: application/x-unknown");
  6. header("Expires: 0");
  7. header("Content-Length: ".$file['size']);
  8. header("Content-Transfer-Encoding: binary");
  9. @header('Content-Disposition: attachment; filename="'.$file['filename'].'"');
  10. if(!fp) die("500");
  11.  
  12. while(!feof($fp)) {
  13. echo fread($fp, 8192); //8KB to bufor paczki (systemowy) - nie radze zmieniać
  14. flush();
  15. usleep(1000000); //Dobierz eksperymentalnie do uzyskania odpowiedniej prędkości
  16. }
  17. fpassthru($fp);
  18. fclose($fp);
  19.  
  20. ?>


--------------------
flexiCMS v2 [|||||||+--] 75% done
Go to the top of the page
+Quote Post

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: 21.08.2025 - 13:09