我具有此php函数,可从我的public_html下载文件。
function download($file){
$dir = "RepList/";
$path = $dir.$file;
if(!file_exists($path))
{
die("Error : The file does not exists !");
}else{
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Typr: application/w3g");
header("Content-Transfer-Encoding: binary");
readfile($path);
}
}
if (isset($_GET['download']))
{
if(!empty($_GET['download']))
{
$file = $_GET['download'];
download($file);
}
}
对于下载,我使用类似:
<a class="download" id="download'.$i.'_" href="../download.php?download='.$cc->EList[$i]->getEName().'" target="_blank">Download</a>
如果我的文件名中带有“&”符号,我将收到“错误:该文件不存在!”。我像1年前一样从事此工作,现在我想修复该错误。
有什么建议吗?简单而快速的事情。
您可能应该使用urlencode()
function并将创建HTML链接更改为:
<a class="download" id="download'.$i.'_" href="../download.php?download='.urlencode($cc->EList[$i]->getEName()).'" target="_blank">Download</a>
否则将&
字符视为url中的变量分隔符
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句