bobleny Posted May 13, 2007 Share Posted May 13, 2007 Is there a way to say, if an image is broken, don't show it? For example, basically, it looks much like this: echo "<img src='snow".$i.".jpg'><br />\r\n"; If for some reason the image is broken, I don't want it to echo the link. This works, but it is really slow! if (fopen("snow".$i.".jpg", 'r')) { echo "<img src='snow".$i.".jpg'><br />\r\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/ Share on other sites More sharing options...
neel_basu Posted May 13, 2007 Share Posted May 13, 2007 [move]First of all Please Dont use a BIG Signature of Such size[/move] -------------------------------------------------------------------------- Ya it can be done Use getimagesize() If the Image is not broken then and only then it will return the Mime type and the Size of that Image else It would return just false. Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-251785 Share on other sites More sharing options...
ToonMariner Posted May 13, 2007 Share Posted May 13, 2007 try if (isfile($i)) { ... } Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-251786 Share on other sites More sharing options...
ToonMariner Posted May 13, 2007 Share Posted May 13, 2007 Please don't post with marquee and moan about big sigs.. I can scroll past them and they bon't bother me... Lets keep replies to to the question - if anyones sig is 'too big' then I am sure admin will say something to them.... Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-251787 Share on other sites More sharing options...
neel_basu Posted May 13, 2007 Share Posted May 13, 2007 I wouldn't Stop Untill He doesn't STOPIf you really Love PHPBB and Fire fox Use Smaller Images.. ------------------------------------[move]First of all Please Dont use a BIG Signature of Such size[/move] ----------------------------------------------------------------------- try if (isfile($i)) { ... } It doesn't say that the IMAGE (Not File) Is Broken or not. It says wheather that is File or not. Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-251788 Share on other sites More sharing options...
bobleny Posted May 13, 2007 Author Share Posted May 13, 2007 ToonMariner, When I use that, I get this error: Fatal error: Call to undefined function isfile() ------------------------------ neel_basu, Uh, for the record, I hate PHPBB... Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-251791 Share on other sites More sharing options...
neel_basu Posted May 13, 2007 Share Posted May 13, 2007 ToonMariner, When I use that, I get this error: Fatal error: Call to undefined function isfile() ------------------------------ neel_basu, Uh, for the record, I hate PHPBB... What profit you will get using that much big Signature Here isfile isn't needed. You need if(getimagesize('file.png')) { echo "File Is OK"; } else { echo "File is Broken"; } Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-251796 Share on other sites More sharing options...
bobleny Posted May 13, 2007 Author Share Posted May 13, 2007 neel_basu, Thank you for the reply. Both "getimagesize()" and "fopen()" seem to work the same. Is there a different way, or should I look into Javascript? --------------------------------- Also, neel_basu, if you are to criticize someones sig, you might consider reading it... No where in my sig does it say anything about PHPBB... :/ Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-251803 Share on other sites More sharing options...
fert Posted May 13, 2007 Share Posted May 13, 2007 file_exists() Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-251804 Share on other sites More sharing options...
neel_basu Posted May 13, 2007 Share Posted May 13, 2007 file_exists() Oh! man why not you are understanding ?? Is there a way to say' date=' if an image is broken, don't show it?[/quote']You are showing wheather the File Exists or not Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-251806 Share on other sites More sharing options...
Rojay Posted May 13, 2007 Share Posted May 13, 2007 i think if the file doesnt exist then its broken so its the same Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-251835 Share on other sites More sharing options...
neel_basu Posted May 13, 2007 Share Posted May 13, 2007 i think if the file doesnt exist then its broken so its the same No A broken image is still a Binary file How can it be File doesn't Exists. Look this is a Broken Image File Attached [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-251877 Share on other sites More sharing options...
Daniel0 Posted May 13, 2007 Share Posted May 13, 2007 neel_basu: If you think a user has a too big signature, then report him to an administrator or moderator. I think you are far more annoying with your marquees and big red text than his signature is. Besides, you can turn viewing of users' signatures off here: http://www.phpfreaks.com/forums/index.php?action=profile;sa=theme Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-251883 Share on other sites More sharing options...
bobleny Posted May 13, 2007 Author Share Posted May 13, 2007 file_exists() doesn't seem to work at all.... If you list images sometimes you get a little tiny square that looks like it's been ripped in half. That could be because the file doesn't exist or because the file is broken. Either way, I want to keep that from being displayed... Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-252141 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 <?php if(getimagesize("image.png")) { echo "<img src=\"image.png\" alt=\"\" />"; } ?> I'd say that's the best way. Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-252147 Share on other sites More sharing options...
neel_basu Posted May 13, 2007 Share Posted May 13, 2007 ~chigley Ya I was just trying to make him understand this ------------- ~bobleny Have you ever used getimagesize() ?? Both "getimagesize()" and "fopen()" seem to work the same. Not not at all. PLease reaqd it from here http://in.php.net/getimagesize It returns Image Hight Weidth , MIME Type etc etc.... So if the Image is broken it cannot get its Size and So it returns False. Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-252152 Share on other sites More sharing options...
bobleny Posted May 13, 2007 Author Share Posted May 13, 2007 I tried it again, but this time I use a larger number. getimagesize() worked fopen() didn't work so well... I will use getimagesize(). Is there a way to say, if getimagesize() fails 4 times consecutively, stop? For example, here is what I actually have: for($r = 1; $r <= $c; $r++) { $i = str_pad($r, $digits, '0', STR_PAD_LEFT); if (getimagesize($before.$i.$after)) { echo "<img src='".$before.$i.$after."'><br />\r\n"; } } Say there are actually only 10 images. Say for some reason $c = 300. The 10 images will work, but the rest will fail because there are only 10 images, right? How do I tell the for loop to stop looping after getimagesize() fails 4 times in a row? Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-252180 Share on other sites More sharing options...
neel_basu Posted May 13, 2007 Share Posted May 13, 2007 if(!isset($cnt)){$cnt = 0} for($r = 1; $r <= $c; $r++) { $i = str_pad($r, $digits, '0', STR_PAD_LEFT); if (getimagesize($before.$i.$after)) { echo "<img src='".$before.$i.$after."'><br />\r\n"; } else { $cnt++;//Incrementing if($cnt >= 4){break;}//Break the Loop Is more than 4 } } Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-252191 Share on other sites More sharing options...
Barand Posted May 13, 2007 Share Posted May 13, 2007 Something like for($r = 1, $fails = 0; $r <= $c; $r++) { $i = str_pad($r, $digits, '0', STR_PAD_LEFT); if (getimagesize($before.$i.$after)) { echo "<img src='".$before.$i.$after."'><br />\r\n"; $fails = 0; // reset on success if you want 4 in a row } else ++$fails; if ($fails > 3) break; } Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-252194 Share on other sites More sharing options...
bobleny Posted May 13, 2007 Author Share Posted May 13, 2007 Thank! It works now. I set it to 300 images, and it only took 29 seconds. It would take at least an hour otherwise! Thanks for all of your help! Quote Link to comment https://forums.phpfreaks.com/topic/51142-solved-is-there-a-way-to-say-if-an-image-is-broken-dont-show-it/#findComment-252199 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.