Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript][PHP] Ajax a header() w PHP - pobieranie pliku
d.stp
post
Post #1





Grupa: Zarejestrowani
Postów: 358
Pomógł: 0
Dołączył: 19.04.2012

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


Mam przycisk który po kliknięciu otwiera okienko. Tam jest formularz w którym użytkownik może wpisać kod. Jeżeli kod jest poprawny, powinno się włączyć pobieranie pliku. Całość mam oparte na php + ajax.

Wiem jak zrobić pobieranie pliku przez header() w php, ale nie wiem jak zwrócić to do JS.

Skrypt PHP wygląda tak:

  1. <?php
  2.  
  3.  
  4. $file = 'plik.rar';
  5. header('Content-Description: File Transfer');
  6. header('Content-Type: application/octet-stream');
  7. header('Content-Disposition: attachment; filename='.basename($file));
  8. header('Content-Transfer-Encoding: binary');
  9. header('Expires: 0');
  10. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  11. header('Pragma: public');
  12. header('Content-Length: ' . filesize($file));
  13. flush();
  14. readfile($file);
  15.  
  16. ?>


JS:

  1. $.ajax({
  2. type: "POST",
  3. url: "check.php",
  4. data: "name="+name+"&pwd="+pwd,
  5. success: function(html){
  6. if (html=='true') {
  7. window.location=html;
  8. }
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 Aktualny czas: 20.08.2025 - 13:20