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
  •  | 
  •  

Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top