1. Rename a file in a directory. The code is shown in Figure 1.

2. Error: rename(E:/wwwroot/avatar/BEIJI/侯森.jpg,E:/wwwroot/avatar/BEIJI/378477.jpg): ϵͳ�Ҳ���ָ�����ļ��� (code: 2), as shown in Figure 2.

3. Use the file_exists function to check if the file exists. If it exists, print 1; if not, print 0, as shown in Figure 3.

4. The printed result is 0, indicating that the file check result is non-existent, as shown in Figure 4.

5. Open the URL: http://php.net/manual/zh/function.rename.php , and find a tip: , to solve this kind of problem, as shown in Figure 5
Translation: On windows (XP, vista, 7 …) http://fr.wikipedia.org/wiki/Windows-1252″, if your filename contains accents, it basically doesn’t work, so use the iconv function from utf-8 to cp1252 as follows:

6. iconv — Convert string to requested character encoding. Convert the string E:/wwwroot/avatar/BEIJI/侯森.jpg from UTF-8 encoding to GB2312. The code is shown in Figure 6.

7. The printed result is 1, indicating that the file check result is existent, as shown in Figure 7.

8. The final implementation code is shown in Figure 8.

9. The files in the directory E:/wwwroot/avatar/BEIJI are shown in Figure 9.

10. Run the script. The file in the directory E:/wwwroot/avatar/BEIJI has been successfully renamed, as shown in Figure 10.

11. Run the script. Error: iconv(): Detected an illegal character in input string, as shown in Figure 11.
Translation: iconv(): Detected an illegal character in input string

12. Print the file name and find that the illegal character should be 吴䶮, as shown in Figure 12.

13. Change GB2312 to GB18030 (if changed to GBK, it still throws an error; the GB18030 character set includes the GBK character set and CJK Ext-A), as shown in Figure 13.

