dflow Posted April 1, 2009 Share Posted April 1, 2009 how can one check if image file exists? for example: i have ../images/image_1.jpg pointing to an image now if i want to check if the image image_1.jpg really exists in the images folder if not show white_blank.jpg Quote Link to comment https://forums.phpfreaks.com/topic/152108-checking-if-image-file-exists-in-folder/ Share on other sites More sharing options...
trq Posted April 1, 2009 Share Posted April 1, 2009 file_exists. Quote Link to comment https://forums.phpfreaks.com/topic/152108-checking-if-image-file-exists-in-folder/#findComment-798840 Share on other sites More sharing options...
MadTechie Posted April 1, 2009 Share Posted April 1, 2009 use the function file_exists() <?php $file = '../images/image_1.jpg'; if(file_exists($file)) { echo "<img src='$file'>"; }else{ echo "<img src='no_image.jpg'>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152108-checking-if-image-file-exists-in-folder/#findComment-798842 Share on other sites More sharing options...
dflow Posted April 7, 2009 Author Share Posted April 7, 2009 use the function file_exists() <?php $file = '../images/image_1.jpg'; if(file_exists($file)) { echo "<img src='$file'>"; }else{ echo "<img src='no_image.jpg'>"; } ?> hi this still doesnt work i get the else result??? Quote Link to comment https://forums.phpfreaks.com/topic/152108-checking-if-image-file-exists-in-folder/#findComment-803533 Share on other sites More sharing options...
Yesideez Posted April 7, 2009 Share Posted April 7, 2009 That means it can't find it so it's your path or the file isn't actually there. Try this: $file = 'images/image_1.jpg'; Quote Link to comment https://forums.phpfreaks.com/topic/152108-checking-if-image-file-exists-in-folder/#findComment-803539 Share on other sites More sharing options...
dflow Posted April 7, 2009 Author Share Posted April 7, 2009 That means it can't find it so it's your path or the file isn't actually there. Try this: $file = 'images/image_1.jpg'; i tried the absolute path and nada !! Quote Link to comment https://forums.phpfreaks.com/topic/152108-checking-if-image-file-exists-in-folder/#findComment-803541 Share on other sites More sharing options...
premiso Posted April 7, 2009 Share Posted April 7, 2009 i tried the absolute path and nada !! Then the image does not exist, bad name or you still have the incorrect path. Simple as that. We, sadly, do not know how your server is setup and cannot help you further, you will have to take steps to debug this on your own. Quote Link to comment https://forums.phpfreaks.com/topic/152108-checking-if-image-file-exists-in-folder/#findComment-803542 Share on other sites More sharing options...
dflow Posted April 7, 2009 Author Share Posted April 7, 2009 what should i look in the server configuration? i simply checked if my logo image exists and got negative Quote Link to comment https://forums.phpfreaks.com/topic/152108-checking-if-image-file-exists-in-folder/#findComment-803561 Share on other sites More sharing options...
premiso Posted April 7, 2009 Share Posted April 7, 2009 Post the full path to the image here. Also post the full path to your script. Alternatively you can try this: $file = $_SERVER['DOCUMENT_ROOT'] . '/images/image_1.jpg'; And see if that works. That will give the correct absolute path to the image using the server variable. Quote Link to comment https://forums.phpfreaks.com/topic/152108-checking-if-image-file-exists-in-folder/#findComment-803567 Share on other sites More sharing options...
dflow Posted April 7, 2009 Author Share Posted April 7, 2009 Post the full path to the image here. Also post the full path to your script. Alternatively you can try this: $file = $_SERVER['DOCUMENT_ROOT'] . '/images/image_1.jpg'; And see if that works. That will give the correct absolute path to the image using the server variable. ok this worked at the end: <?php $filename = 'images/citybanner22.jpg'; if (file_exists($filename)) { echo "<img src=../$filename>"; } else { echo "The file $filename does not exist"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152108-checking-if-image-file-exists-in-folder/#findComment-803672 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.