Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Zmiana nazwy pliku i pobranie go...
kuba_pilach
post 4.10.2011, 19:49:24
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
nospor
post 4.10.2011, 19:51:03
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Zmieniasz nazwe pliku z $name na plik.sta, następnie sprawdzasz czy $name istnieje i się głupio dziwisz, że nie isntieje :/
No jak ma istnieć, skoro linijke wcześniej zmieniłeś mu nazwę?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
kuba_pilach
post 4.10.2011, 19:55:07
Post #3





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

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


Hahahaha, na taki prymityw dałem się złapać... Aż mi śmiesznie biggrin.gif
Go to the top of the page
+Quote Post
nospor
post 4.10.2011, 19:58:09
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Powinno ci być głupio a nie śmiesznie. Tu nie ma się z czego śmiać, conajwyżej płakać.... tongue.gif
Na przyszłość zastanów się odrobinę dłużej niż kubuś puchatek....myślenie jest trudne, ale można się do niego przyzwyczaić.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

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 Wersja Lo-Fi Aktualny czas: 19.06.2025 - 14:22