how to access documents(.pdf .doc etc) which are stored outside of the root folder [duplicate]

StackOverflow https://stackoverflow.com/questions/12779538

  •  05-07-2021
  •  | 
  •  

Question

Possible Duplicate:
How to serve documents from outside the web root using PHP?

Basically this is one of my first sites, however some of the documents my client wants to store contain sensitive information, so i have read up and it seems the best way to approach this is to store the documents outside of the root folder.

However if they are stored oustide of the root folder how would I go about letting the client access them for download?

Was it helpful?

Solution

Simply readfile() when you tell browser to download it

$file = '/outsite/website/file.doc';
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=" . basename($file));
header("Content-Type: " . mime_content_type($file));
header("Content-Length: " . filesize($file));
header("Content-Transfer-Encoding: binary");
readfile($file);
exit;

Remember that Apache must have access to it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top