Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Zmiana nazwy pliku i pobranie go...
kuba_pilach
post
Post #1





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

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


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


I pisze: File not found.
Wie ktoś, jak to poprawić?
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: 24.08.2025 - 17:46