php中文文件is_file检验失败(编码问题)
2016-02-04 17:46
459 查看
php中判断文件是否存在我们会使用file_exists函数或is_file函数,但在使用file_exists时如果你文件名或路径是中文在uft8编码文档时是无效。
iconv函数用法详解介绍: http://www.php100.com/html/php/hanshu/2013/0905/4691.html
mb_convert_encoding方法说明: http://www.yiibai.com/manual/php/function.mb-convert-encoding.html
mb_detect_encoding检查字符串编码: http://php.net/manual/zh/function.mb-detect-encoding.php
$realname='中文.txt'; //后面加上一个"//IGNORE"就可以是ICONV()函数忽略错误,继续执行 $realname = iconv("UTF-8","GB2312//IGNORE",$realname); //同“iconv”效果一样 //$realname = mb_convert_encoding($realname, "GB2312", "auto"); if(file_exists($realname)) { // 若不进行GB2312转码,永远都进不了这里 } else { echo '文件不存在 ...'; }
iconv函数用法详解介绍: http://www.php100.com/html/php/hanshu/2013/0905/4691.html
mb_convert_encoding方法说明: http://www.yiibai.com/manual/php/function.mb-convert-encoding.html
mb_detect_encoding检查字符串编码: http://php.net/manual/zh/function.mb-detect-encoding.php
相关文章推荐
- yii 知识点
- Win7 iis配置ftp
- Yii2 高级版新建一个 Api 应用
- 分享几个基于 Yii2 的开源项目
- thinkphp3.2之模型(M层)
- PHP图片压缩的方法
- PHP图片压缩的方法
- 教你在Yii2.0框架中如何创建自定义小部件
- Yii2 自定义独立验证器
- Yii2 使用 Beanstalk 队列系统
- Yii2 注册表单验证规则 手机注册时候使用短信验证码
- Yii2 高级模板 多域名管理问题
- ThinkPHP - URL - 伪静态 - 路由 - 重写
- ThinkPHP - 配置项目结构
- 怎样配置PHP环境和安装Zendstdio编辑器
- PHP生成缩略图,控制图片质量,支持.png .jpg .gif
- PHP安全过滤函数
- yii2-lock-form 也许这就是你想要的,阻止表单多次提交
- PHP---正则表达式
- PHP日期与时间戳转换