« 上一篇下一篇 »

下面这段代码是不能够返回正确值的代码,无论文件是否在都返回不在:

 

下面这段代码是不能够返回正确值的代码,无论文件是否在都返回不在:

1
2
3
4
5
6
<?php;
$file="/attachment/21/0/中文.rar";
$newfile = dirname(__FILE__).$file;
 
echo file_exists($newfile);
?>

经过测试之后,增加了一句将UTF8编码转换为GB2312编码的语句,就可以正确判断了:

1
2
3
4
5
6
7
8
<?php
$file="/attachment/21/0/中文.rar";
$newfile = dirname(__FILE__).$file;
 
$file=iconv('UTF-8','GB2312',$file);
 
echo file_exists($newfile);
?>