Home> php教程> PHP源码> body text

php move_uploaded_file 中文乱码问题或上传失败问题

WBOY
Release: 2016-06-08 17:27:40
Original
1191 people have browsed it

php是外国人做的,在中文支持上有些地方做得不完美,就在我们文件上传时就发现了,上传中文竟然不成功,
下面我们来看看实例与解决方法吧。
*/
$filepath ='upfile/';

if ($_FILES['file']['error']==0)
{

if( move_uploaded_file($_FILES['file']['tmp_name'],$filepath.$_FILES['file']['name']))
{
echo '文件上传成功';
}
else
{
echo '文件上传失败';
}
}


/*
.....
上面是一段简单的文件上传代码,传英语的是没有问题,但是中文的就不会成功了,好了,那我们如何处理中文文件名上传失败问题呢。
方法很简单就是对上传的文件名重命名就OK了,下面我们把程序修改一下。如下。
*/

if ($_FILES['file']['error']==0){

$ext = end(explode('.',$_FILES['file']['name']));
$fileRandName = time(); //根据当前时间生成一个字符串

if( move_uploaded_file($_FILES['file']['tmp_name'],$filepath.$fileRandName.'.'.$ext))
{
echo '文件上传成功';
}
else
{
echo '文件上传失败';
}
}

//这样不管你上传的是什么文件都OK了。
//本站原创文章转载注明来自www.111cn.net

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!