Jump to content

Help with file exists


thefollower

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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.