I have the following file hierarchy :
- downloader.php (to download the files only through the php page for logged in users and block direct access through .htaccess file )
- 10-C-Language (a directory containing some pdf files )
- C Language 2019 First + notes.pdf (a pdf file contained in "10-C-Language" directory)
The link sent to the downloader.php is as follows:
downloader.php?file=10-C-Language/C%20Language%202017%20First%20%20+%notes.pdf
but it returns
File does not exist.
although the file does exist !
here is the php code for the downloader:
<?php
include('session.php');
if (isset($_GET['file'])) {
//Read the filename
$filename = $_GET['file'];
//Check the file exists or not
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$allowed = array('pdf', 'txt', 'docx', 'rar', 'zip', 'jar');
if (!in_array($extension, $allowed)) {
echo 'You don't have permission to download this type of files.';
} else {
if (file_exists($filename)) {
//Define header information
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: 0");
header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
header('Content-Length: ' . filesize($filename));
header('Pragma: public');
ob_clean();
//Clear system output buffer
flush();
//Read the size of the file
readfile($filename);
//Terminate from the script
die();
} else {
echo "File does not exist.";
}
}
} else
echo "Filename is not defined."
?>
Some files are containing spaces ,but they are downloaded fine ,but for other cases like the ond described above it doesn't work !
So what is the problem here ?!
Regards