Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 757
Val Avatar asked Aug 18 '26 12:08

Val


2 Answers

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';
like image 56
Gumbo Avatar answered Aug 21 '26 02:08

Gumbo


$file = rawurldecode('images/thumbs/1%20-%20Copy.jpg');
like image 36
bcosca Avatar answered Aug 21 '26 01:08

bcosca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!