Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Zmiana rozszeżenia pliku podczas pobierania
Forum PHP.pl > Forum > Przedszkole
kuba_pilach
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 ?
Ilware
przesyłasz nazwę pliku razem z rozszerzeniem

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


spróbuj usunąć rozszerzenie i dodać swoje jakie chcesz pobrać
kuba_pilach
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ł...
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.