下載其中文件名有&的文件問題。PHP下載逃跑&在文件名中下載
例如,一個名爲bla的文件將會正常下載,但bla & Blaaaaa找不到該文件。
有沒有辦法讓我逃脫&?
我無法重命名服務器上的文件,這會更容易但不可能。
文件存儲在數據庫中,然後檢索並修剪其獨特附件。 :)
$fileName = $eachFile['filename'];
$fileNamePretty = explode('__', $fileName); // ONLY FILENAME
,然後在下載鏈接我:
<a href="../download.php?filename=<?php echo $fileName?>">
和的download.php
<?php
require 'core/init.php';
$filename = $_GET['filename'];
$dir = "training/trainingDocuments/";
$downloadFilename = $dir.$filename;
//8 - SUBSEA QUESTIONS__51f034ab37a8e.xls
//if the filename exists
if(is_file($downloadFilename)){
//send the headers
header('Pragma: public'); //FIX IE6 Content-Disposition
header('Content-Description: File Transfer');
header('Content-Transder-Encoding: binary');
header(sprintf('Content-Length: %u', filesize($downloadFilename)));
header('Content-type: application/octet-stream');
header("Content-Disposition: attachment; filename=".$downloadFilename."");
readfile($downloadFilename);
$training->addToDownload($filename);//updates download count
}else{
//file doesn't exist
echo "File no exist\n\n";
echo $downloadFilename;
感謝所有幫助
你試圖逃脫與通過URL編碼的URI? –