Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Problem ze skryptem pobierania plików
piotrekk
post
Post #1





Grupa: Zarejestrowani
Postów: 123
Pomógł: 2
Dołączył: 13.11.2006

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


Mam problem ze skryptem pobierania plików. Znalazłem ten kod na forum i podobno działa,
jednak jak pod firefoxem nie ma problemów to pod IE wyskakuję błąd, że nie może pobrać pliku i że go nie ma.

Skrypt:
  1. $fileName = $_GET['file'];
  2. $sciezka = "../files/".$id."/".$fileName;
  3.  
  4.  
  5. header("Content-Disposition: attachment; filename=".$fileName."");
  6. header('Content-Type: application/x-unknown');
  7.  
  8. if ($fp = fopen($sciezka, 'rb'))
  9. {
  10. flock($fp, 1);
  11. echo(fread($fp, filesize($sciezka)));
  12. flock($fp, 3);
  13. fclose($fp);
  14. }


Jakieś propozycję i rozwiązania ?
Go to the top of the page
+Quote Post
potreb
post
Post #2





Grupa: Zarejestrowani
Postów: 1 568
Pomógł: 192
Dołączył: 7.03.2005
Skąd: Warszawa

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


Przykład żywcem zerżnięty z manuala:
  1. <?php
  2.  
  3. $sf = dbquery("SELECT * FROM `files` WHERE `fid` = '".$_GET['fid']."'");
  4. dbquery("UPDATE `files` SET `fcdown` = fcdown+1 WHERE `fid` = '".$_GET['fid']."'") or die(mysql_error());
  5. $r = dbobject($sf);
  6.  
  7. $url = UPLOADIR . $r->furl;
  8. if(file_exists(UPLOADIR.$r->furl)) {
  9. header('Content-Description: File Transfer');
  10. header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
  11. header('Pragma: public');
  12. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  13. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  14. // force download dialog
  15. header('Content-Type: application/force-download');
  16. header('Content-Type: application/octet-stream', false);
  17. header('Content-Type: application/download', false);
  18. header('Content-Type: '.$r->fmime.'', false);
  19. // use the Content-Disposition header to supply a recommended filename
  20. header('Content-Disposition: attachment; filename="'.basename($url).'";');
  21. header('Content-Transfer-Encoding: binary');
  22. header('Content-Length: '.filesize($url));
  23. flush();
  24. readfile($url);
  25. } else {
  26. redirect("errors.php?p=434");
  27. }
  28. ?>


Dostosuj pod swój skrypt i powinno chulać, IE trochę inaczej wszystko widzi.


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

Go to the top of the page
+Quote Post
piotrekk
post
Post #3





Grupa: Zarejestrowani
Postów: 123
Pomógł: 2
Dołączył: 13.11.2006

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


Dzieki,
działa.

Testowałem ten przykład z manuala ale też w IE pokazuję bład:

  1. <?php
  2. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
  3. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  4. header("Content-type: application/zip;\n"); //or yours?
  5. header("Content-Transfer-Encoding: binary");
  6. $len = filesize($filename);
  7. header("Content-Length: $len;\n");
  8. $outname="downfile.zip";
  9. header("Content-Disposition: attachment; filename=\"$outname\";\n\n");
  10.  
  11. readfile($filename);
  12. ?>
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 Aktualny czas: 20.08.2025 - 10:22