The solution to the problem that the file_exists function in PHP does not support Chinese names, _PHP tutorial

WBOY
Release: 2016-07-13 10:22:11
Original
824 people have browsed it

The file_exists function in PHP does not support Chinese names,

Generally speaking, file_exists() is often used in PHP to determine whether a file or folder exists. If it exists, it returns true, otherwise it returns false. However, when the web page uses UTF8 encoding, this function cannot return the correct value for Chinese file names or folder names, and always returns false. After testing, we came up with a solution and analyzed that the reason for this situation should be that PHP cannot make correct judgments due to different encodings.

The following code is code that cannot return the correct value. It returns that the file is not present regardless of whether it exists:

<&#63;php;
$file="/attachment/21/0/中文.rar";
$newfile = dirname(__FILE__).$file;

echo file_exists($newfile);
&#63;>

Copy after login

After testing, a sentence is added to convert UTF8 encoding to GB2312 encoding, and the correct judgment can be made:

<&#63;php
$file="/attachment/21/0/中文.rar";
$newfile = dirname(__FILE__).$file;

$file=iconv('UTF-8','GB2312',$file);

echo file_exists($newfile);
&#63;>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/851352.htmlTechArticleThe file_exists function in PHP does not support Chinese names. Generally speaking, file_exists() is often used in PHP to determine a certain Whether the file or folder exists, if it exists, return true, otherwise...
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 Tutorials
More>
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!