我在php中创建了一个下载函数,其中的文件包含特殊字符。但在下载文件时,文件名从一些特殊字符中断。主要是在获取文件名中的空格时。我的下载函数是这样的。
function download(){
$filename = "google _(){}[]valentine~!@#$%^&*()_+`1=-.flv";
$filepath = "uploads/" . $filename;
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
//setting content type of page
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=" . $filename);
header("Content-Description: File Transfer");
//Read File it will start downloading
readfile($filepath);
}发布于 2012-03-09 20:12:33
您应该尝试使用"\“来转义空格。
如下所示:
$filename = str_replace( ' ', '\ ', $filename );发布于 2012-03-09 16:28:36
你试过使用urlencode吗?
http://au.php.net/manual/en/function.urlencode.php
http://au.php.net/manual/en/function.urldecode.php
https://stackoverflow.com/questions/9630815
复制相似问题