PHP Nette - how to download files above the www directory (from root)
Hello,
I would need to use a function on my website, which is written in PHP Nette, that would allow downloading files outside the usual path of web / www / uploads from web / uploads, ie. from a directory at the same level as app, vendor, www ... How could this be solved? The goal is that the file path is not visible to the visitor and cannot be downloaded by "tipping" the file path. Thanks
Hello
yes, I handle downloading above the www directory in Nette as follows:
I would need to use a function on my website, which is written in PHP Nette, that would allow downloading files outside the usual path of web / www / uploads from web / uploads, ie. from a directory at the same level as app, vendor, www ... How could this be solved? The goal is that the file path is not visible to the visitor and cannot be downloaded by "tipping" the file path. Thanks
REPLY
Hello
yes, I handle downloading above the www directory in Nette as follows:
public function getFile($up_id)
{
$document_root = $_SERVER['DOCUMENT_ROOT'];
//odebere www na konci v ceste $document_root
$path = substr($document_root, 0, -3);
$file = $this->getUpload($up_id);
$file = $path . $file->up_path;
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
}
return $file;
}