suess0r Posted January 30, 2007 Share Posted January 30, 2007 hey,i'm trying to display images that exist in my web folder /images and if not then to use my default image. Here's the code i'm using, but unfortunetely i keep getting the default image no matter what. Is there another way to see if the image exists other than the way i'm doing it... do i need to search the full directory before the /images/clubs/logos/ folder??[quote] $defaultImage = "/images/clubs/logos/default.jpg"; $myImage = "/images/clubs/logos/".$id.".jpg"; if (file_exists($myImage)) { $img = $myImage; } else { $img = $defaultImage; } echo '<p align="center"><img src="'.$img.'" align="center" width="300" height="128"></p>';[/quote] Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 30, 2007 Share Posted January 30, 2007 You can use [b]file_exists[/b]. Quote Link to comment Share on other sites More sharing options...
suess0r Posted January 31, 2007 Author Share Posted January 31, 2007 I did use [b]file_exists[/b], did u not look at the code i posted? but i still keep getting a default image, so there's a problem with my path to $myImage because it's not recognizing if/when they do exist. Anyone give a little help? Do i need to check a full ServerPath or something, or entire URL before it? Anyone give a little help please. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 31, 2007 Share Posted January 31, 2007 You need to use the full path likely. What is the relation of the /images folder to the folder this file is in? Quote Link to comment Share on other sites More sharing options...
suess0r Posted January 31, 2007 Author Share Posted January 31, 2007 the file is in the directory directly above the images folder. this is the full path...http://www.clb411.com/images/default.jpghttp://www.clb411.com/pg2.php -> calls the imagei did put that full path in the code above for the default and file_exists image and i'm still getting my default image every time. i did an echo just on the file_exists part and it still doesn't find the images that exist. Is there another full path i need to add? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 31, 2007 Share Posted January 31, 2007 Can you post the new code?Where is $id coming from? It's possible it's not set.Do print $id; to make sure it's what you expect. Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted January 31, 2007 Share Posted January 31, 2007 The problem may be that when your start with a slash [b]/[/b] I think the server looks from the server root, not the document root. So you can use [code] $myImage = $_SERVER['DOCUMENT_ROOT'] . "images/clubs/logos/".$id.".jpg";[/code] I think should work. Quote Link to comment Share on other sites More sharing options...
suess0r Posted January 31, 2007 Author Share Posted January 31, 2007 the $id is the clubID and I have named all the images in the logo folder the (clubid.jpg). Here's the loop i'm running through and the $id obviously changes with each club, so i would assume that the $myImage would change as well, but Shogun even after I used the $_SERVER[] path you gave me i'm still getting default images.. maybe i'm missing something.. here's my loop--above SQL Query commands left out--[quote]for ($i = 0; $i < mysql_num_rows($result_set); $i++) { $landmark = mysql_result($result_set, $i, "Club_Landmark"); $city = mysql_result($result_set, $i, "Club_City"); $name = mysql_result($result_set, $i, "Club Name"); $address = mysql_result($result_set, $i, "Club Address"); $phone = mysql_result($result_set, $i, "Club Phone Number"); $state = mysql_result($result_set, $i, "Club State"); $id = mysql_result($result_set, $i, "ClubID"); if ($i % 2) { $bg_color="#D7F57E"; } else { $bg_color="#E1F5A4"; } echo ' <tr>'; $defaultImage = "http://www.clb411.com/images/clubs/logos/default.jpg"; $myImage = $_SERVER['DOCUMENT_ROOT'] . "images/clubs/logos/".$id.".jpg"; if (file_exists($myImage)) { $img = $myImage; } else { $img = $defaultImage; } echo '<td width="25%" wrap bgcolor="'.$bg_color.'"> <b><p align="center"><a href="pg3.php?id='.$id.'"><img src="'.$img.'" align="center" width="190" height="93"></a></p> </td> <td width="75%" nowrap bgcolor="'.$bg_color.'"> <font face="arial" size="2">'; echo '<b>Name:</b> <a href="orl3.php?id='.$id.'">'.$name.'</a>'; echo ' <br> <b>Address: </b>'.$address.' <br> <b>Phone: </b><a href="tel:'.$phone.'">'.$phone.'</a> <br> </font> </td> </tr> <tr> <td width="70%" nowrap bgcolor="'.$bg_color.'"> <td>'; } } else { echo 'Sorry, no results were found...'; }[/quote] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 31, 2007 Share Posted January 31, 2007 But what happens when you print out $myImage?Just ignore the loop for a moment and do <img src="'.$myImage.'" />Does it even show up? Does the image actually exist? What is the value of myImage at this point? Quote Link to comment Share on other sites More sharing options...
suess0r Posted January 31, 2007 Author Share Posted January 31, 2007 thanks for your patience jesi, no i did an echo on <img src="'.$myImage.'" /> and the images can't be displayed so they aren't showing they exist. They do indeed exist because the way i have it now i do my call like this...<a href="pg3.php?id='.$id.'"><img src="/images/clubs/logos/'.$id.'.jpg" align="center" width="60" height="45"></a>and it prints out the logos fine, but the ones that don't exist i have an ugly no image [x]... so they do exist. Quote Link to comment Share on other sites More sharing options...
suess0r Posted January 31, 2007 Author Share Posted January 31, 2007 any ideas? 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.