I am having a problem accessing a file on my web server after restructuring the routes. After restructuring the files to download are stored in the address :
http://mysite/submission/uploads/test.txt
Previously it was stored in:
http://mysite/uploads/test.txt
and so the path /uploads/test.txt would work when reading from the database. Iv recently updated the routes as visible in the first sample and have updated the content in the mongodb database. However as the uploads folder is in root and the download.php file is in the submission folder the path from the database im assuming points to:
http://mysite/mydownloadpage/submission/uploads/test.txt
in my database it contains the text to the path exactly as follows:
submission/uploads/test.txt
I tried to append the prefix to the string to point up a directory back to root, but it does not function:
../submission/uploads/test.txt
This seems to result in it including the '..' instead of pointing it to the root directory.
Here is the download function which gets passed the path from the database:
function download($path){
if(!file_exists($path)){
die('Error');
}else{
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename='.basename($path));
header('Content-Type: application/octet-stream');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
ob_start();
flush();
readfile($path);
exit;
}
}
if (isset($_GET['download'])) {
if (!empty($_GET['download'])) {
$file = $_GET['download'];
download($file);
}
}
Any help would be appreciated.