php下载不适用于&;

php下载不适用于&;,php,download,Php,Download,我有这个php函数从我的公共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 T

我有这个php函数从我的公共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>

如果我的文件名中有“&”符号,我将收到“错误:文件不存在!”。 我在一年前就开始做这个了,现在我想修复这个错误


有什么建议吗?简单快速。

您可能应该使用
urlencode()
函数并将创建HTML链接更改为:

<a class="download"  id="download'.$i.'_" href="../download.php?download='.urlencode($cc->EList[$i]->getEName()).'" target="_blank">Download</a>


否则,
&
字符将被视为url中的变量分隔符内容类型:这只是一个输入错误吗?如果不是,则是扩展名wrong@user2039923user602088想问,您的代码中的“contenttypr”是否存在拼写错误?它应该是“内容类型”。@ShaunakShukla$\u-GET会自动进行URL解码,所以您不需要它在dowload()中的什么位置?我在html中更改了,现在我收到的文件不存在于所有项目中。@user2039923您不需要在我添加到此处的任何位置添加urldecode。。。urlencode($cc->EList[$i]->getEName())。“target=“\u blank”>Download@Marcin纳比亚莱克:谢谢,我知道,但当我在这里读到urlencode()时,我的脑海里一片空白,所以在评论中添加了urlencode()。你说得对!!