preetham Posted September 8, 2013 Share Posted September 8, 2013 Hi, I am trying to check if image exits on some url, if so then display it. This works fine if I have image locally and use file_exists() When i pass url file_exits(), it fails. Any help appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/281990-file_exists-doesnt-work-for-images-on-url/ Share on other sites More sharing options...
cataiin Posted September 8, 2013 Share Posted September 8, 2013 Link for image? Quote Link to comment https://forums.phpfreaks.com/topic/281990-file_exists-doesnt-work-for-images-on-url/#findComment-1448750 Share on other sites More sharing options...
cataiin Posted September 8, 2013 Share Posted September 8, 2013 I can't edit my post. Try this: <?php $image = "http://forums.phpfreaks.com/uploads/profile/photo-thumb-165140.jpg"; if(@getimagesize($image) !== false) { echo "<img src=".$image." />"; } else { echo "Nop."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/281990-file_exists-doesnt-work-for-images-on-url/#findComment-1448751 Share on other sites More sharing options...
preetham Posted September 9, 2013 Author Share Posted September 9, 2013 I can't edit my post. Try this: Thanks. This seems to be working fine. However, i see some performance issue, I mean , it takes 3 secs more time now. Is it because of this or something else? Quote Link to comment https://forums.phpfreaks.com/topic/281990-file_exists-doesnt-work-for-images-on-url/#findComment-1448797 Share on other sites More sharing options...
cataiin Posted September 9, 2013 Share Posted September 9, 2013 Thanks. This seems to be working fine. However, i see some performance issue, I mean , it takes 3 secs more time now. Is it because of this or something else? You can store the files on your server temporarily and then use getimagesize. Quote Link to comment https://forums.phpfreaks.com/topic/281990-file_exists-doesnt-work-for-images-on-url/#findComment-1448803 Share on other sites More sharing options...
vinny42 Posted September 9, 2013 Share Posted September 9, 2013 First, Don't use getimagesize() for this, it downloads the whole image. Use cURL, which can ask the remote server for only the HTTP headers, which will return status=200 or status=404, etc. Second: ofcourse there is a performance issue if you are going to verify each image every time, which is why you would cache the results in a file somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/281990-file_exists-doesnt-work-for-images-on-url/#findComment-1448812 Share on other sites More sharing options...
preetham Posted September 9, 2013 Author Share Posted September 9, 2013 You can store the files on your server temporarily and then use getimagesize. for storing it on my server, i can use file_exists itself. I'm having issue for remote images. First, Don't use getimagesize() for this, it downloads the whole image. Use cURL, which can ask the remote server for only the HTTP headers, which will return status=200 or status=404, etc. Second: ofcourse there is a performance issue if you are going to verify each image every time, which is why you would cache the results in a file somewhere. Thanks for the advice, I will check on this asap. Quote Link to comment https://forums.phpfreaks.com/topic/281990-file_exists-doesnt-work-for-images-on-url/#findComment-1448825 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.