Home >Backend Development >PHP Problem >How to solve the problem of garbled Chinese characters in php image names

How to solve the problem of garbled Chinese characters in php image names

藏色散人
藏色散人Original
2021-09-18 10:25:342626browse

Solution to the Chinese garbled picture name in php: 1. Open the background code file; 2. Modify the content to "move_uploaded_file($_FILES["userfile"]["tmp_name"],"img/" . iconv( "UTF-8","...")".

How to solve the problem of garbled Chinese characters in php image names

The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer

How to solve the problem of garbled Chinese image names in PHP?

Record to solve the problem of garbled Chinese image names when uploading images in the PHP background

Generally, garbled characters appear because the PHP encoding is different from the encoding on the system. (The encoding of PHP is utf-8, my system is windons, so the encoding is GBK)

Let me first describe my problem: use When PHP uploads pictures to a directory on my local disk, the Chinese name of the picture will be garbled.

Generally, you will use the move_uploaded_file function in the background to store the temporary file where you want to store it.

So just change

move_uploaded_file($_FILES["userfile"]["tmp_name"], "img/" . $_FILES["userfile"]["name"]); 
// img/是我当前目录下的文件

to

move_uploaded_file($_FILES["userfile"]["tmp_name"],"img/" . iconv("UTF-8","gb2312", $_FILES["userfile"]["name"]));

to solve the garbled code problem.

Recommended study: "PHP Video Tutorial"

The above is the detailed content of How to solve the problem of garbled Chinese characters in php image names. For more information, please follow other related articles on the PHP Chinese website!

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