0
我已經將文件上傳到我的webroot文件夾以外的文件夾,並使用一些php代碼在通過數據庫驗證後檢索文件。我的代碼似乎工作,即檢索文件,我唯一的問題是,上傳的pdf包含空格的文件名和下面的代碼似乎只檢索空間前的第一個單詞。檢索根外的文件,避免切斷包含空格的文件名
示例文件名是 我到London.pdf 野生動物攝影部分次數1.pdf
除了通過數據庫和文件phuycical去而代以每個文件包含下劃線代替空間,有沒有一種方法,我可以改變下面的代碼,所以它檢索整個文件名?
我想我可以用%20代替文件名,如果它檢測到一個空間,但不起作用。
/* Done some processing above to retrieve the $filename for the pdf */
$file = 'h:'.$filename;
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);
exit;