0

I've made a script that takes a dir, and scnas through that dir for image files, and then echo's out these images on a jquery-gallery.

However, some of these dir's contain special chars like (æ,ø,å) - and it does not seem to work, even though the dir-variable is set, with the correct chars.

Does File_exist handle special chars?

This code work, but it's not great, cause I have to replace the æ,ø and å's with "_". And likewise do this on all my folders.

$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."'/>";
        }
    }
}    
TehHO
  • 43
  • 4

1 Answers1

0

Okay then why didn't you use your favorite search engine before posting here?

You can find the answer here: special characters in "file_exists" problem (php)

Community
  • 1
  • 1
Daniel M
  • 3,369
  • 20
  • 30