JTapp Posted May 11, 2008 Share Posted May 11, 2008 Does anybody know how I can display the ALT words "The image is not available" to the following line - so I can get rid of that little red "x" when the image isn't available? echo "<img src='" . $imagesFolder . $row['CompanyID'] . ".jpg' /></p>"; Quote Link to comment https://forums.phpfreaks.com/topic/105189-solved-display-an-alt-tag-when-an-image-is-missing/ Share on other sites More sharing options...
fred123 Posted May 12, 2008 Share Posted May 12, 2008 I'm no expert (just waiting for my question to be answered, but... $imagelink = $imagesFolder.$row['CompanyID']; if (file_exists($imagelink)) { echo "<img src='".$imagelink.".jpg' /></p>"; } else { echo "<img src='".$imagelink.".jpg' alt='The image is not available' /></p>"; } should work? Quote Link to comment https://forums.phpfreaks.com/topic/105189-solved-display-an-alt-tag-when-an-image-is-missing/#findComment-538610 Share on other sites More sharing options...
JTapp Posted May 12, 2008 Author Share Posted May 12, 2008 Thanks for trying! I tested it and got a blank page.. Quote Link to comment https://forums.phpfreaks.com/topic/105189-solved-display-an-alt-tag-when-an-image-is-missing/#findComment-538613 Share on other sites More sharing options...
fred123 Posted May 12, 2008 Share Posted May 12, 2008 My fault i think, i used quotation marks on the ALT. I've changed it now. Use ' and " or put backslashes before them IE \". Quote Link to comment https://forums.phpfreaks.com/topic/105189-solved-display-an-alt-tag-when-an-image-is-missing/#findComment-538616 Share on other sites More sharing options...
Barand Posted May 12, 2008 Share Posted May 12, 2008 <?php $imagefile = "$imagesFolder{$row['CompanyID']}.jpg"; if (file_exists($imagefile)) echo "<img src='$imagefile' />"; else echo "<img src='default.jpg' alt='The image is not available'/>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/105189-solved-display-an-alt-tag-when-an-image-is-missing/#findComment-538617 Share on other sites More sharing options...
JTapp Posted May 12, 2008 Author Share Posted May 12, 2008 Well, its pretty close. I'm getting the message, but it keeps the red "x". [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/105189-solved-display-an-alt-tag-when-an-image-is-missing/#findComment-538656 Share on other sites More sharing options...
DarkWater Posted May 12, 2008 Share Posted May 12, 2008 That's due to your browser. Nothing you can do about that unless you make an image that you put up that says like "Sorry, image unavailable!"...like on Photobucket or Tinypic. Quote Link to comment https://forums.phpfreaks.com/topic/105189-solved-display-an-alt-tag-when-an-image-is-missing/#findComment-538661 Share on other sites More sharing options...
LooieENG Posted May 12, 2008 Share Posted May 12, 2008 Well, how about just this? (unless I didn't read the thread properly and it has to be an alt tag) <?php $imagefile = "$imagesFolder{$row['CompanyID']}.jpg"; if (file_exists($imagefile)) echo "<img src='$imagefile' />"; else echo "The image is not available"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/105189-solved-display-an-alt-tag-when-an-image-is-missing/#findComment-538662 Share on other sites More sharing options...
JTapp Posted May 12, 2008 Author Share Posted May 12, 2008 LooieENG - It didn't have to be an ALT tag.. thanks much!!! Quote Link to comment https://forums.phpfreaks.com/topic/105189-solved-display-an-alt-tag-when-an-image-is-missing/#findComment-538681 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.