I've configured a file download, but in some cases files can't be downloaded. Because the file_exist isn't true, the php code dies and gives me back the defined error message.
Why does the download work fine with a comma OR space in the directory, but fails with BOTH a comma followed with a space?
The file with download error:
$the_download = "/share/Multimedia/Library1/John, Doe/test/cover.jpg";
The files that download ok:
$the_download = "/share/Multimedia/Library1/John,Doe/test/cover.jpg";
$the_download = "/share/Multimedia/Library1/John Doe/test/cover.jpg";
code:
$the_filename = "somefilename.jpg";
if (file_exists($the_download)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($the_filename));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($the_download));
flush();
readfile($the_download);
exit;
}
else die("File not found<br>" . $the_download);
you should enclose the filename in the header with double quotes like this :
header('Content-Disposition: attachment; filename="'.basename($the_filename).'");