Jump to content

Displaying either Default image vs Image that exists?!?!


suess0r

Recommended Posts

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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

the file is in the directory directly above the images folder. this is the full path...

http://www.clb411.com/images/default.jpg
http://www.clb411.com/pg2.php -> calls the image

i 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?
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.