有特殊字符和模具的好奇心

时间:2012-08-24 08:45:58

标签: php special-characters directory file-exists

我制作了一个脚本,它带有一个目录,并通过该目录扫描图像文件,然后在jquery-gallery上回显这些图像。

然而,这些目录中的一些包含特殊的字符,如(æ,ø,å) - 并且即使设置了dir-variable,它也似乎没有用到正确的字符。

File_exist是否处理特殊字符?

这段代码工作,但它不是很好,因为我必须用“_”替换æ,ø和å。同样在我的所有文件夹上执行此操作。

$invalid_chars = array('æ','ø','å');

//Find the dir with the photos
$dir = 'img/products/'.str_replace($invalid_chars,'_', $category)."/".str_replace($invalid_chars,'_',$model);

//accepted filetypes
$file_display = array('jpg','jpeg','png');


if(file_exists($dir)==false){
echo "</br><center>A team of highly trained monkeys has been dispatched to deal with this situation.</center></br></br><br /><br /></br>";
}
else 
{
    $dir_contents = scandir($dir);
    foreach($dir_contents as $file){

        $file_type = explode('.',$file);
        $file_type = strtolower(end($file_type));

        if($file!=='.' && $file!=='..' && in_array($file_type, $file_display) == true) { 
        echo "<img src='".$dir."/".$file."'/>";
        }
    }
}    

1 个答案:

答案 0 :(得分:0)

那么为什么你不在发布之前使用自己喜欢的搜索引擎?

您可以在此处找到答案:special characters in "file_exists" problem (php)