Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Pobieranie pliku za pomocą PHP
mishka49
post
Post #1





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 15.07.2013

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


Witam znalazłem taki kawałek kodu
  1.  
  2. $url = 'http://strona.pl/plik.zip';
  3. $file = basename($url);
  4.  
  5. $fp = fopen($file, 'w');
  6.  
  7. $ch = curl_init($url);
  8. curl_setopt($ch, CURLOPT_FILE, $fp);
  9.  
  10. $data = curl_exec($ch);
  11.  
  12. curl_close($ch);
  13. fclose($fp);
  14.  
  15. header('Content-Description: File Transfer');
  16. header('Content-Type: application/octet-stream');
  17. header('Content-Disposition: attachment; filename='.basename($file));
  18. header('Content-Transfer-Encoding: binary');
  19. header('Expires: 0');
  20. header('Cache-Control: must-revalidate');
  21. header('Pragma: public');
  22. header('Content-Length: ' . filesize($file));
  23. readfile($file);

ale plik zamiast zostać pobrany jest wyświetlany w przeglądarce, co może być tego przyczyną?

Ten post edytował mishka49 22.10.2013, 19:08:38
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 6)
fate
post
Post #2





Grupa: Zarejestrowani
Postów: 824
Pomógł: 106
Dołączył: 14.03.2012
Skąd: Warszawa

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


sprobuj dac header (location, $file) i zakomentowac 26 linijke
ale to moze byc "drewniana" metoda


--------------------
Go to the top of the page
+Quote Post
mishka49
post
Post #3





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 15.07.2013

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


Niestety nawet to nie działa
Go to the top of the page
+Quote Post
Turson
post
Post #4





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


  1. //$d - sciezka do pliku
  2. header("Content-Length: " . filesize($d));
  3. header("Content-Transfer-Encoding: binary");
  4. header("Content-Disposition: attachment; filename=" . basename($d));
Go to the top of the page
+Quote Post
mishka49
post
Post #5





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 15.07.2013

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


Cytat(Turson @ 22.10.2013, 23:09:01 ) *
  1. //$d - sciezka do pliku
  2. header("Content-Length: " . filesize($d));
  3. header("Content-Transfer-Encoding: binary");
  4. header("Content-Disposition: attachment; filename=" . basename($d));


Genialne. Dużo krótszy kod a działa jak ta lala. Wielkie dzkęki
Go to the top of the page
+Quote Post
Matimor
post
Post #6





Grupa: Zarejestrowani
Postów: 287
Pomógł: 10
Dołączył: 22.08.2009

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


Pamiętaj żeby przetestować te rozwiązanie pod każdą przeglądarką. Z doświadczenia wiem, że są z tym problemy smile.gif


--------------------
Go to the top of the page
+Quote Post
mishka49
post
Post #7





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 15.07.2013

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


Na większośći przeglądarek działa, ale nie wiedzieć czemu podczas ściągania pliku serwer jakby umiera, tzn. plik dalej jest pobierany ale nie można odświeżyć strony, dlaczego?
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: 22.08.2025 - 07:54