gazalec Posted February 6, 2007 Share Posted February 6, 2007 i was wondering if it is possible to have an if statement with image for example <? if("<img src='directory/pic.jpg'> == '' "){ echo "<img src='directory/alternativepic.jpg'>"; }else{ echo "<img src='directory/pic.jpg'>"; } ?> if this isn't possible then does anyone know how to get this effect Thanks Link to comment https://forums.phpfreaks.com/topic/37312-if-statement-with-images/ Share on other sites More sharing options...
trq Posted February 6, 2007 Share Posted February 6, 2007 if this isn't possible then does anyone know how to get this effect Your code is invalid and from your example it is difficult to tell what it is exactly your trying to do. Could you provide and explination in english? Link to comment https://forums.phpfreaks.com/topic/37312-if-statement-with-images/#findComment-178336 Share on other sites More sharing options...
kenrbnsn Posted February 6, 2007 Share Posted February 6, 2007 You need to use the file_exists() in your "if" statement. One way follows: <?php $img = (file_exists('directory/pic.jpg'))?'pic':'alternativepic'; echo '<img src="directory/' . $img . '.jpg">'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/37312-if-statement-with-images/#findComment-178337 Share on other sites More sharing options...
gazalec Posted February 6, 2007 Author Share Posted February 6, 2007 ok sorry i'm in the process of making a website with ALOT of products so instead of all the products having a separate page i'm making one php page that will call the products ID from a database and display everything needed so instead of having 500 pages i have 1, the only problem is some of the images dont have an image and i just wanted it so that if there is no image it displays an alternative image sayin, No image available or something along those lines and i was just wondering if it would be possible for PHP to look in the folder and if it doesn't find an image it displays the alternative. thanks Link to comment https://forums.phpfreaks.com/topic/37312-if-statement-with-images/#findComment-178345 Share on other sites More sharing options...
EagerWolf Posted February 6, 2007 Share Posted February 6, 2007 I guess you d like to check if image exists? Or .. if image is not blank file? If you'd like to check if image exists try this: <?php if (file_exsists('dir/img.jpeg') { echo "<img src='dir/img.jpeg'>"; } ?> If you'd like to check if image is not a blank file than the code would be: <? $minsize = "1000000"; //in bytes $filepath = "dir/img.jpeg"; if ($minsize < filesize($filename)) { echo "<img src='dir/img.jpeg'>"; } ?> Hope this is it! Link to comment https://forums.phpfreaks.com/topic/37312-if-statement-with-images/#findComment-178351 Share on other sites More sharing options...
kenrbnsn Posted February 6, 2007 Share Posted February 6, 2007 See my answer in reply #2. Ken Link to comment https://forums.phpfreaks.com/topic/37312-if-statement-with-images/#findComment-178352 Share on other sites More sharing options...
EagerWolf Posted February 6, 2007 Share Posted February 6, 2007 <?php if (file_exsists('dir/img.jpeg') { echo "<img src='dir/img.jpeg'>"; } else { echo "<img src='dir/subimg.jpeg'>"; } ?> Link to comment https://forums.phpfreaks.com/topic/37312-if-statement-with-images/#findComment-178353 Share on other sites More sharing options...
gazalec Posted February 6, 2007 Author Share Posted February 6, 2007 ok thanks guys that worked Link to comment https://forums.phpfreaks.com/topic/37312-if-statement-with-images/#findComment-178354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.