PHP中file_exists函数不支持中文名的解决方法
2014-07-26 11:04
260 查看
一般来说PHP中常使用file_exists()判断某个文件或者文件夹是否存在,如果存在则返回true,否则返回false。但是该函数在网页使用UTF8编码的情况下,对于中文的文件名或者文件夹名不能返回正确值,始终返回false。经测试之后得出解决方法,分析造成这一情况的原因应该是编码不同而导致的PHP不能正确判断。
下面这段代码是不能够返回正确值的代码,无论文件是否在都返回不在:
<?php; $file="/attachment/21/0/中文.rar"; $newfile = dirname(__FILE__).$file; echo file_exists($newfile); ?>
经过测试之后,增加了一句将UTF8编码转换为GB2312编码的语句,就可以正确判断了:
<?php $file="/attachment/21/0/中文.rar"; $newfile = dirname(__FILE__).$file; $file=iconv('UTF-8','GB2312',$file); echo file_exists($newfile); ?>
您可能感兴趣的文章:
相关文章推荐
- PHP中file_exists函数不支持中文名的解决方法
- PHP中file_exists函数不支持中文名的解决方法
- 配置Nginx支持php,出现No input file specified错误的解决方法
- ie 无法下载中文名文件 解决方法 【修改IIS5注册表可以支持中文文件名】
- IIS不支持PHP的解决方法
- PHP错误Parse error: syntax error, unexpected end of file in test.php on line 12解决方法
- Web_PHP_DedeCMS_全站更新出现“ DedeTag Engine Create File False”错误解决方法;
- linux上的php环境默认不支持bcdiv函数解决方法
- php5.3 不支持 session_register() 此函数已启用的解决方法
- Apache下PHP Loaded Configuration File None 解决方法
- PHP的file_exists函数不支持UTF-8编码下的中文文件目录路径
- PHP学习之路之PHP文件上传需要考虑的问题以及解决方法($_FILES,$_SERVER,substr,strrpos,file_exists,move_uploaded_file,is_uploaded_file,mkdir)
- PHP PDO sqlite ,Unable to Open database file的解决方法
- PHP错误Parse error: syntax error, unexpected end of file in test.php on line 12解决方法
- 【转】linux下apache支持中文名的解决方法!(mod_encoding安装手册)
- PHP imagick-3.1.0RC2无法安装,提示fatal error: wand/MagickWand.h: No such file or directory 解决方法
- 解决php smarty 2.x register_object方法不支持多级对象方法调用的问题
- IIS不支持中文名的解决方法
- 5.4php不支持dede的解决方法
- 学习php需要了解的点4 - PHP中file_get_contents函数抓取https地址出错的解决方法