Page 1 of 1

display a default image?

Posted: Wed May 31, 2006 7:26 pm
by direland
Is there an "if" statement I can use to check if an image exists in a certain directory, and if it does display it, but if it doesn't exist then display another image in a different directory? I've written simple "if" statements for text display, but nothing like this. Is this possible?

It might help to tell the scenario. I am putting together templates for teacher web sites. If they wish, they can upload their own logo into their upload directory to display at the top of the page, but if they choose not to upload their own logo I want the default (district) logo to appear there. The default logo is located in another directory on the same server.

Thanks in advance!

Posted: Wed May 31, 2006 8:01 pm
by ambivalent
Same concept as text, you probably want to do this, or some variant thereof:

Code: Select all

$target = "path/to/pic.png";

$default = "path/to/default.png";

if(file_exists($target) && is_file($target))

{
	echo "<img src=\"$target\" />";
}

	else

{
	echo "<img src=\"$default\" />";
}

Posted: Wed May 31, 2006 10:37 pm
by direland
Thanks! This worked perfectly!