login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Handige scripts > File openen in pagina

File openen in pagina

Auteur: php.net - 14 december 2008 - 11:36 - Gekeurd door: Stijn - Hits: 3879 - Aantal punten: (0 stemmen)



Ik kwam dit script tegen op php.net en ik vond hem zeer handig.

Als je bijv. een downloadsysteem op je site hebt, is dit handig omdat je dan onzichtbaar een file in een pagina kan openen.

Code:
  1. <?php
  2. function download($path) {
  3. // fix for IE catching or PHP bug issue
  4. header("Pragma: public");
  5. header("Expires: 0"); // set expiration time
  6. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  7. // browser must download file from server instead of cache
  8.  
  9. // force download dialog
  10. header("Content-Type: application/force-download");
  11. header("Content-Type: application/octet-stream");
  12. header("Content-Type: application/download");
  13.  
  14. // use the Content-Disposition header to supply a recommended filename and
  15. // force the browser to display the save dialog.
  16. header("Content-Disposition: attachment; filename=".basename($path).";");
  17.  
  18. /*
  19.   The Content-transfer-encoding header should be binary, since the file will be read
  20.   directly from the disk and the raw bytes passed to the downloading computer.
  21.   The Content-length header is useful to set for downloads. The browser will be able to
  22.   show a progress meter as a file downloads. The content-lenght can be determines by
  23.   filesize function returns the size of a file.
  24.   */
  25. header("Content-Transfer-Encoding: binary");
  26. header("Content-Length: ".filesize($path));
  27.  
  28. @readfile($path);
  29. }
  30. ?>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (3)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.02s