Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Dlaczego skrypt nie kończy się wyskakującym okienkiem
finito
post 25.02.2014, 18:47:09
Post #1





Grupa: Zarejestrowani
Postów: 110
Pomógł: 0
Dołączył: 16.12.2012

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


No właśnie. Usiłuję napisać skrypt php, który pozwoli na ściąganie plików z serwera na dysk. Niby wszystko działa, ale po kliknięciu na link, okienko zapisywania się nie wyskakuje.

Może ma ktoś pomysł dlaczego?
index.php:
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>Nawigacja po katalogach</title>
  6. </head>
  7. <body>
  8. <div>
  9. <?php
  10. $downloadpath="./download/";
  11. function wypisz($downloadpath)
  12. {
  13. $fd = opendir($downloadpath);
  14. if (!$fd) return false;
  15. while (( $file = readdir($fd))!==false)
  16. {
  17. if (is_dir($downloadpath.$file)) continue;
  18. echo "<a href=\"http://www.php.bartoszszmit.cba.pl/download.php?name=";
  19. echo "$file\">$file</a><br>";
  20. }
  21. closedir($fd);
  22. }
  23. wypisz($downloadpath);
  24. ?>
  25. </div>
  26. </body>
  27. </html>

download.php
  1. <?php
  2. $downloadpath="/download/";
  3. function checkFileName($name,$downloadpath)
  4. {
  5. $fd = opendir($downloadpath);
  6. if (!fd) echo "nie udało się otworzyć katalogu";
  7. $result=false;
  8. while (($file = readdir($fd))!==false)
  9. {
  10. if (is_dir($downloadpath.$file)) continue;
  11. if ($file==$name)
  12. {
  13. $result=true; break;
  14. }
  15. }
  16. closedir($fd);
  17. return $result;
  18. }
  19. function send($file,$downloadpath)
  20. {
  21. if (!file_exists($downloadpath.$file))
  22. { echo "nie ma takiego pliku";
  23. return;
  24. }
  25. $fd = fopen($downloadpath.$file,'r');
  26. $filesize = filesize($downloadpath.$file);
  27. $contents = fread($fd,$filesize);
  28. fclose($fd);
  29. header("Content-Type:application/octet-stream");
  30. header("Content-Length:$filesize");
  31. header("Content-Disposition:attachment;file=$file");
  32. echo $contents;
  33. if (isSet($_GET['name']))
  34. {
  35. if (!checkfileName($name,$downloadpath))
  36. {
  37. echo "nie ma takiego pliku na serwerze";
  38. }
  39. else
  40. {
  41. send($_GET['name'],$downloadpath);
  42. }
  43. }
  44. else { echo "nie ma takiego pliku na serwerze";}
  45. }
  46.  
  47. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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.07.2025 - 08:54