I’ve seen tutorials over the internet for this, but I cannot get it to work.
I’ve got this in a while loop, but it shouldn’t matter:
while($row = mysql_fetch_object($result)){
$image_url = $deviceimg.($row->Image);
if(!file_exists($image_url))
{}
else {
$image_url = 'images/android.png';
}
Basically, im my database, all the rows called Image are populated, but only some of them have an actual file. What im trying to do is check to see if the image file actually exists on the server, if it doesn’t use a default image (images/android.png)
No matter that I do, it will either replace ALL images with the default, or it will just use the URL in the database, regardless of if the file actually exists.
The reason you have a problem is because you have wrapped
$image_urlin single quotes when you pass it tofile_exists(). This is checking whether there is a file file literally named$image_url, instead of using the contents of the variable.Change
to
and it will work.