search
Homephp教程PHP源码php move_uploaded_file 中文乱码问题或上传失败问题

<script>ec(2);</script>

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

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version