$upfile=$_FILES['files'];
if (empty($upfile['name'])){
$this->error('未选择文件');
exit;
}
$name = $upfile["name"];
$tmp_name = $upfile["tmp_name"];
if(move_uploaded_file($tmp_name,'upload/'.$name))
{
echo "上传成功";
}
else echo "上传失败";
上传英文标题的能上传 中文的不能上传这是为什么啊?
如果只是中文文件名, 可能是浏览器编码问题。
解决方法:
可以设置浏览器兼容支持, 参考:
$ua = $_SERVER["HTTP_USER_AGENT"];
$filename = "中文 文件名.txt";
$encoded_filename = urlencode($filename);
$encoded_filename = str_replace("+", "%20", $encoded_filename);
header('Content-Type: application/octet-stream');
if (preg_match("/MSIE/", $ua)) {
header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
} else if (preg_match("/Firefox/", $ua)) {
header('Content-Disposition: attachment; filename*="utf8/'/'' . $filename . '"');
} else {
header('Content-Disposition: attachment; filename="' . $filename . '"');
}
2. 修改保存的文件名