【问题标题】:Curiousity with special chars and dirs对特殊字符和模具的好奇心
【发布时间】:2012-08-19 19:33:24
【问题描述】:

我已经制作了一个脚本,它需要一个目录,并通过该目录的 scnas 获取图像文件,然后在 jquery-gallery 上回显这些图像。

但是,其中一些目录包含特殊字符,例如 (æ,ø,å) - 即使设置了 dir 变量并使用正确的字符,它似乎也不起作用。

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."'/>";
        }
    }
}    

【问题讨论】:

  • 你在哪个操作系统上测试这个?
  • 本地主机,在 Windows 7 机器上...

标签: php special-characters directory file-exists


【解决方案1】:

好的,那你为什么在发帖之前不使用你最喜欢的搜索引擎呢?

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

【讨论】:

    猜你喜欢
    • 2011-01-16
    • 1970-01-01
    • 1970-01-01
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    • 2022-11-16
    • 2017-10-29
    • 2012-09-24
    相关资源
    最近更新 更多