Posted By

tylerhall on 07/05/06


Tagged

textmate download pdf save content


Versions (?)

Who likes this?

21 people have marked this snippet as a favorite

alvaroisorna
Fixe
panatlantica
jkochis
Taleamus
kawikak
groenewege
millisami
raws
bitcrumb
apocalip
chucktrukk
srpsco
nb109
Hollow
mecha
tspitzr
lfcortes
wirenaught
pelted
ashloren


Serve external document for download


 / Published in: PHP
 

This lets you serve up a file for download without revealing the actual URL of the file. Useful for protected downloads or dynamic content coming from a database. The first header() line isn't always needed. It's just there to help Acrobat on Windows behave properly. If you're not returning PDFs, you can (usually) safely remove it.

  1. function download_document($filename, $path = "", $mimetype = "application/octet-stream")
  2. {
  3. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4. header("Content-Disposition: attachment; filename = $filename");
  5. header("Content-Length: " . filesize($pathto . $filename));
  6. header("Content-Type: $mimetype");
  7. echo file_get_contents($pathto . $filename);
  8. }

Report this snippet  

You need to login to post a comment.