parlanchina Posted February 22, 2014 Share Posted February 22, 2014 Hello, I have a script that shows dynamic images, this is the script: <img src="<?php echo $data['thumbnailUrl'];?>" alt="" border="0" width="122" height="92">When there is no image - $data['thumbnailUrl'], broken image box is displayed. How can I edit this script so when there is no a dynamic image, a static one will show instead?THANKS! Quote Link to comment Share on other sites More sharing options...
denno020 Posted February 22, 2014 Share Posted February 22, 2014 Simply use an if statement to check if the thumbnailUrl array index is set in your $data variable. If it is, echo the value, otherwise, echo the path to your static image. Denno Quote Link to comment Share on other sites More sharing options...
WebStyles Posted February 23, 2014 Share Posted February 23, 2014 you can just check if the file exists: if(is_file($data['thumbnailUrl'])){ // show the dynamic image }else{ // show the static one } Quote Link to comment Share on other sites More sharing options...
parlanchina Posted February 23, 2014 Author Share Posted February 23, 2014 Thanks for your reply. This is what I tried but it does not work. Do you know what might be wrong? <img src="<?php if(is_file($data['thumbnailUrl'])){<img src="<?php echo $data['thumbnailUrl'];?>" alt="" border="0" width="122" height="92"></a>}else{<img src="noimage.jpg" width="168" height="128" alt="" /></a>}?>" alt="" border="0" width="122" height="92"></a> Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 23, 2014 Share Posted February 23, 2014 (edited) Your code should be <?php if(is_file($data['thumbnailUrl'])){ ?> <img src="<?php echo $data['thumbnailUrl'];?>" alt="" border="0" width="122" height="92"> <?php }else{ ?> <img src="noimage.jpg" width="168" height="128" alt="" /> <?php } ?> Edited February 23, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
parlanchina Posted February 23, 2014 Author Share Posted February 23, 2014 Thanks for the help Ch0cu3r. When I use this code now all image show noimage.jpg and the dynamic image does not show at all. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 23, 2014 Share Posted February 23, 2014 Maybe use empty instead of is_file Quote Link to comment Share on other sites More sharing options...
parlanchina Posted February 23, 2014 Author Share Posted February 23, 2014 This also shows only noimage.jpg Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 23, 2014 Share Posted February 23, 2014 What is the output of var_dump($data['thumbnailUrl']) Quote Link to comment Share on other sites More sharing options...
parlanchina Posted February 23, 2014 Author Share Posted February 23, 2014 No it does not work but actually when I right-click the code of a listing that does not have image, this is what it comes up- http://imagesus.homeaway.com/mda01/1b79ecc4-46fe-49fe-bb75-ac1ec359a177.1.3. It points to an image but it is broken. When I rightclick a working image (example of working image http://imagesus.homeaway.com/mda01/fb6c745c-a3cb-46c4-972d-4ab934a635ab.1.3) it show image type JPEG and for the broken images it shows image type Not Available. Is it possible to structure the script so if it is not a jpeg, gif or png, it will show noimage? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 23, 2014 Share Posted February 23, 2014 Does all images that appear broken have the following url http://imagesus.homeaway.com/mda01/1b79ecc4-46fe-49fe-bb75-ac1ec359a177.1.3 Quote Link to comment Share on other sites More sharing options...
parlanchina Posted February 23, 2014 Author Share Posted February 23, 2014 No, it seems all broken images = 0kb. is it possible to modify the script in a way so if the image size = 0kb it will display the noimage? Quote Link to comment 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.