Page 1 of 1

If file exists show image uploaded else show no image file

Posted: Wed Sep 03, 2008 12:23 pm
by admin2gd1
Here is something quick someone can help me with. I can't get the second image to show.

If the photo in the database and directory doesn't exist then show image 2 but it's not doing it because it is still trying to read from the directory where the photos would be, so it ignores the second image in less that directory does not exist also.

Now the thing is I have 12 photos all together in one directory and the directory needs to exist for the other 11 photos so what I want is the second image to show and not try to read from the directory.

This is my code that I am using, don't worry about $SITEurl and $username and $name they are working.

Code: Select all

<?php if(file_exists("../photos/properties/$username/$name/$photo1")){ ?>
<img class="photo" src="<?php echo $SITEurl ?>/photos/properties/<?php echo $username; ?>/<?php echo $name; ?>/<?php echo $photo1; ?>" alt="">
<?php }else{ ?><img class="photo" src="<?php echo $SITEurl; ?>/images/<?php echo getLang(noimage); ?>" alt=""><?php } ?>

Re: If file exists show image uploaded else show no image file

Posted: Wed Sep 03, 2008 12:37 pm
by Sindarin
I don't see anything that would tell the script (while loop) to list the whole folder,

I use this for my cms wherever it needs to check and show an image inside a while loop to get all the entries,
It gets the path from database and tries to find the image,
if it does it displays it.
If it doesn't find an entry it ouputs "without image" and if it doesn't find the file
it outputs an option to clean up the false entry.

Code: Select all

 
 
while($row = mysql_fetch_array($db_fetch))
  {
  $newsid=$row['news_id'];
  $newsimage=$row['news_thumbnail'];//Check for images
if ($newsimage=="")
        {
        echo "Without image";
        }
        else
        {
        $file_check="$newsimage";
        if (file_exists($file_check))
        {
        echo "<img src='$newsimage' border=0 alt='Image' />";
        }
        else
        {
        echo "<font color='red'><img src='files/images/layout/cms-alert.png' border=0 alt='Warning' /> Image has been deleted from the server but entry in the database exists! </font>[ <a href='show.php?action=cleanupimage&imagesrc=$newsimage'> CleanUp </a> ]";
        }
        }
 
}

Re: If file exists show image uploaded else show no image file

Posted: Wed Sep 03, 2008 12:40 pm
by starram
Try using this, if this doesn't work then try to give absolute path in the file_exists functions. If that doesn't work too try to give document root path like this:
Note this is just an example: user/html/httpdocs/photos/properties

Code: Select all

<?php 
    if(file_exists("../photos/properties/$username/$name/$photo1"))
    { 
?>
        <img class="photo" src="<?=$SITEurl?>/photos/properties/<?=$username?>/<?=$name?>/<?=$photo1?>" alt="" />
<?php 
    }else{ 
?>
    <img class="photo" src="<?=$SITEurl?>/images/<?=getLang(noimage)?>" alt="" />
<?php   
    } 
?>