Search code examples
phpfile-exists

php weird file_exists bug


Has anyone got any idea to why doesn't the following work ?

$file = 'images/thumbs/1%20-%20Copy.jpg';
if(!file_exists($file)){
 die('NOT THERE');  
}

echo 'Yes its there.';

The problem is with the spaces. I have checked the file exists,dbl checked n triple checked im going nuts. :(

Help


Solution

  • file_exists works on the file system and not via HTTP. So %20 will not be recognized as space but literally as %20; use spaces instead:

    $file = 'images/thumbs/1 - Copy.jpg';