Jump to content

Recommended Posts

My "file exist" function doesn't seem to work.. it claims the image is found when i quite obviously do not have the image on my server, so it shows well nothing... other than test =/

 

This is what i have:

 

<?php
While($row = mysql_fetch_assoc($Get)){
$Image = $row['Image'];
$Check = '/images/userprofiles/'.$Image;
$RecordID = $row['RecordID'];
if (file_exists($Check)) {
?>
<img src="/images/userprofiles/<?php echo $Image;?>" width="100px" height="150px">
<br>TEST<br>
<?php
	}Else{
	$DELETE = mysql_query("DELETE FROM userimages WHERE RecordID='$RecordID'")
		Or die(mysql_error());
}
}
?>

 

What did i do wrong?

Link to comment
https://forums.phpfreaks.com/topic/124509-help-with-file-exists/
Share on other sites

Edit: neil.johnson beat me to it, but only because I was writing some code.

 

I'm assuming the 'Image' value from the query is returning a null or empty value. So, file_exists() is returning true because the FOLDER '/images/userprofiles/' exists!

 

While($row = mysql_fetch_assoc($Get))
{
    if ($row['Image']) //Ensure a value was returned
    {
        if (file_exists('/images/userprofiles/'.$row['Image']))
        {
            echo "<img src=\"/images/userprofiles/<?php echo $Image;?>\" width=\"100px\" height=\"150px\">\n";
            echo "<br>TEST<br>\n";
        }
        else
        {
            $query = "DELETE FROM userimages WHERE RecordID='{$row['RecordID']}'";
            mysql_query($query) or die(mysql_error());
        }
    }
}

 

FYI: This makes no sense

$DELETE = mysql_query("DELETE FROM userimages WHERE RecordID='$RecordID'")

 

What do you plant to do with the variable $DELETE? Unless the query is returning data, there is no need to assign a variable to the query call. Also, I changed the script to reduce some of the variables created. In most instances it makes no sense to create a variable just to use it only once or twice (e.g. $Image & $RecordID)

@mjdamato you cannot use PHP tags/code within an echo:

            echo "<img src=\"/images/userprofiles/<?php echo $Image;?>\" width=\"100px\" height=\"150px\">\n";

That line should be

            echo "<img src=\"/images/userprofiles/$Image\" width=\"100px\" height=\"150px\">\n";

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.