Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Zmiana rozszeżenia pliku podczas pobierania
kuba_pilach
post
Post #1





Grupa: Zarejestrowani
Postów: 224
Pomógł: 3
Dołączył: 24.12.2010

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


Witam!
Mam kod pobierania:
  1. //First, see if the file exists
  2. if (!is_file($name)) { die("<b>404 File not found!</b>"); }
  3.  
  4. //Gather relevent info about file
  5. $len = filesize($name);
  6. $filename = basename($name);
  7. $file_extension = strtolower(substr(strrchr($filename,"."),1));
  8.  
  9. //This will set the Content-Type to the appropriate setting for the file
  10. switch( $file_extension ) {
  11. case "txt": $ctype="text/plain";
  12. case "csv": $ctype="text/plain";
  13. break;
  14.  
  15. default: $ctype="application/force-download";
  16. }
  17.  
  18. //Begin writing headers
  19. header("Pragma: public");
  20. header("Expires: 0");
  21. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  22. header("Cache-Control: public");
  23. header("Content-Description: File Transfer");
  24.  
  25. //Use the switch-generated Content-Type
  26. header("Content-Type: $ctype");
  27.  
  28. //Force the download
  29. @$header="Content-Disposition: attachment; filename=".$filename.";";
  30. header($header );
  31. header("Content-Transfer-Encoding: binary");
  32. header("Content-Length: ".$len);
  33. @readfile($name);


No i oczywiście ob_start i ob_end_flush() nie braknie... ;]
Ale cały czas pobiera w txt... jak zmienić na sta ?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
Ilware
post
Post #2





Grupa: Zarejestrowani
Postów: 248
Pomógł: 31
Dołączył: 14.12.2010
Skąd: Wrocław

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


przesyłasz nazwę pliku razem z rozszerzeniem

  1. @$header="Content-Disposition: attachment; filename=".$filename.";";


spróbuj usunąć rozszerzenie i dodać swoje jakie chcesz pobrać


--------------------
Jeżeli pomogłem kliknij "Pomógł" :)
Go to the top of the page
+Quote Post
kuba_pilach
post
Post #3





Grupa: Zarejestrowani
Postów: 224
Pomógł: 3
Dołączył: 24.12.2010

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


Zamiast $filename dałem sta i pobrało: sta.txt
A gdy rozłożyłem filename funkcją explode i dałem $filename[1].".sta
To pobrało csv.sta.txt ;]

Ma ktoś jeszcze jakiś pomysłquestionmark.gif?
Próbowałem różnych rzeczy i różne dziwne rzeczy mi się zdarzały ;]
Nadal czekam na pomysł...

Ten post edytował kuba_pilach 22.08.2011, 17:12:01
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:27