Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php]prosty problem z downloadem
-Gość_Piotr-
post
Post #1





Goście







A więc mam taki button:
Kod
<INPUT TYPE='button' VALUE='pobierz' onClick=" parent.location.href='http://jakis_tam_adres/~konto/download/plik.txt' ">


jak wymusić na przeglądarce by zaczeła sciągać ten plik a nie otwierała go w przeglądarce ? I jeszce takie pytanie... Jak ze względów bezpieczeństwa najlepiej jest zaplanować moduł sciągania (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) Z tego co czytałęm to jak sie ma dostęp do mysql to robi się linki postaci ./download.php?id=0 gdzie w bazie kolejnym numerkom przypisuje się kolejne pliki. Czy jest jakaś inna koncepcje ? Z góry dzięki za odpowiedź
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
-Gość_Piotr-
post
Post #2





Goście







nie czaje za bardzo o co chodzi (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Jak powinien być przekazany ten argument $_GET['file'] zeby to podziałało (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Bo jak robię tak to jakoś nie idzie:

  1. //plik download.html
  2. <?php
  3. if ($handle = opendir("./download/")) {
  4. while (false !== ($file = readdir($handle))) { 
  5. if ($file != "." && $file != "..") { 
  6. echo "<td align='left'>";
  7. echo "<font color='red'>$file</font> </td>";
  8. echo "<td><INPUT TYPE='button' VALUE='pobierz' onClick=\" parent.location.href='http://adres_serwera/konto/download.php?file=$file'\">"; 
  9. $k++;
  10. echo "</td>";
  11. echo "</tr><tr>";
  12. }
  13.  
  14. }
  15. closedir($handle); 
  16. }
  17. ?>
  18.  
  19.  
  20. //-------------------------------------------------------
  21. //plik download.php
  22. <?php
  23. $file=$_GET['file'];
  24. header("Content-Type: application/force-download"); 
  25. header("Content-Type: application/octet-stream"); 
  26. header("Content-Type: application/download"); 
  27. header("Content-Disposition: attachment; filename=".basename($file).";"); 
  28. header("Accept-Ranges: bytes"); 
  29. header("Content-Transfer-Encoding: binary"); 
  30. header("Content-Length: ".filesize($file)); 
  31. readfile($file); 
  32. exit(); 
  33. ?>
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: 6.10.2025 - 09:17