开发者

php weird file_exists bug

开发者 https://www.devze.com 2023-01-27 20:36 出处:网络
Has anyone got any idea to why doesn\'t the following work ? $file = \'images/thumbs/1%20-%20Copy.jpg\';

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. :(

H开发者_如何学Pythonelp


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';


$file = rawurldecode('images/thumbs/1%20-%20Copy.jpg');


try these two

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号