标签:upload 取名字 字符集 gb2312 utf-8 info 代码 ext dos
在windos中文系统上要求传入的参数如果有中文必须是GBK编码
1、用iconv()转换字符集代码如下
$target_pt = ‘./uploads/‘.uniqid().‘-‘.$images[‘name‘];
//windows下支持中文名字上传
$upload_file_pt = iconv("UTF-8", "GB2312", $target_pt);
if (!move_uploaded_file($images[‘tmp_name‘], $upload_file_pt)) {
$GLOBALS[‘error_message‘] = ‘上传失败‘;
return;
}
2、直接自己取名字用uniqid()获取名字,用pathinfo()获取后缀名代码如下
$ext=pathinfo($_FILES[‘avatar‘][‘name‘], PATHINFO_EXTENSION);
$target = ‘uploads/‘.uniqid().‘.‘.$ext;
if (!move_uploaded_file($_FILES[‘avatar‘][‘tmp_name‘], $target)) {
$GLOBALS[‘error_message‘] = ‘上传文件失败‘;
return;
}
php中函数move_uploaded_file()移动中文文件报错的解决方法
标签:upload 取名字 字符集 gb2312 utf-8 info 代码 ext dos
原文地址:https://www.cnblogs.com/afew/p/9182075.html