Jump to content

Recommended Posts

[code]
<?php
if (is_file(FULL_PATH_TO_YOUR_IMAGE))
{
$path = FULL_PATH_TO_YOUR_IMAGE;
}
else
{
$path = '/common/images/default.jpg';
}
$size = getimagesize($path);
?>
<p align="center">
<img src="<?php echo $path; ?>" <?php echo $size[3]; ?> />
</p>
[/code]

Thats a nice way of doing it - even adjusts for the height and width of the images incase they change!
Link to comment
https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154402
Share on other sites

here's how i have it set up and i'm about to try those other ways

but it's not working...

    $defaultImage = "/images/clubs/logo/default.jpg";

            $myImage = "/images/clubs/logos/".$id.".jpg";
           
            if (file_exists($myImage)) {
              $img = $myImage;
            } else {
              $img = $defaultImage;
            }

echo '<b><p align="center"><img src="'.$img.'" align="center" width="300" height="128"></p>';
Link to comment
https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154403
Share on other sites

can you copy and past the html your script generates please..

try

if (file_exists($_SERVER['DOCUMENT_ROOT . $myImage))

see if that helps - sometimes i have a bit of bother with tgetting the path correct - purely because I am a lazy ass and can't be bothered to pay attention until someone else points out what I have doen wrong.
Link to comment
https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154422
Share on other sites

OK so i've found out the root of the problem why it keeps posting the Default image no matter what....

[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]

i did an echo on $myImage and it was the correct name of the image, and after the if statement i did an echo $img and it's default.jpg no matter what... so the if statement isn't working correctly with the file_exists() function... i tried the file_exists($_SERVER['DOCUMENT_ROOT.$myImage)) but the syntax isn't right...

IS there a better way to see if the file exists?!?
Link to comment
https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154474
Share on other sites

suppose is_file is slighlty more desirable in this case but they do similar things.

remember that while html understands that '/images/this.jpg' is the same as 'http://www.asite.com/images/this.jpg' php doesn't. the string you put in there MUST let the scrip locate it from where teh scriupt is on teh server - which is why I tend to use $_server['document_root']
Link to comment
https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154519
Share on other sites

/images is not your root folder. If images is a sub folder of the folder this php file is in you can do ./images
Otherwise you need your whole path which would be like $_server['document_root'].'/images..etc (or $_server['document_root'].'images...etc)

Link to comment
https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154525
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.