Page 1 of 2

Is This Possible

Posted: Wed Jun 09, 2004 7:30 am
by luketheduck
Something I want to implement on my site, but don't know if it's possible.

The page searches for an image to display based upon 2 variables which are set at page load.

What I want to do is search the directory for the image, but if it doesn't exist, to display a default image instead.

Is this going to be possible? Would be based around an if statement I guess, if image doesn't exist, show xxx instead.

Posted: Wed Jun 09, 2004 8:05 am
by Saethyr
Yes this is possible and extremely easy. Do you have an example of how you would use such a thing?

Posted: Wed Jun 09, 2004 8:08 am
by patrikG
I'm using for this purpose

Code: Select all

<?php
//returns an image
//if no image-file is found, it returns default "blank.gif"
	if (file_exists('graphix/'.$_GET["image"].'.gif')){
		$image="http://www.mydomain.org/graphix/".$_GET["image"].".gif";
	}
	else{
		$image="http://www.mydomain.org/graphix/blank.gif";
	}
	header("Location: $image");
?>

Posted: Wed Jun 09, 2004 8:12 am
by luketheduck
Yes that is exactly what I was looking for...

Thanks!

Posted: Wed Jun 09, 2004 8:22 am
by Grim...
I use getimagesize, that way you can format the image.

Assume $img_var is your image filename.

Code: Select all

<?php
if (@$img = getimagesize($img_var))
{
    print "<img src="$img_var" width="$img[0]" height="$img[1]">";
}
else
{
    print "<img src="blank.gif">";
}
?>

Posted: Wed Jun 09, 2004 8:23 am
by Saethyr
See How You Are Patrik....

I was gonna make him work for it ;)

Posted: Wed Jun 09, 2004 8:26 am
by patrikG
You're right Saethyr - I shouldn't have posted the solution. I am such a spoilsport... ;)

Alas, just after I posted it I thought: "Damn, Saethyr has a point." But then, hey, I did. So, no dessert for me tonight (and it would have been fresh, juicy mango...:()

Posted: Wed Jun 09, 2004 8:27 am
by Grim...
Yum.

Everyone round Patrik's house for dinner :)

Posted: Wed Jun 09, 2004 8:32 am
by patrikG
Hey, I am voluntarily chastising myself and that is usually done in solitude. But you can come around after I'm finished chastising ;)

Posted: Wed Jun 09, 2004 9:00 am
by Grim...
Sussex is a bit of a train ride, though...

Can you post me the dinner?

Posted: Wed Jun 09, 2004 9:05 am
by patrikG
We're talking dessert, not dinner. Dinner is mine :)

there ya go:
Image

Bon appetit.

Posted: Wed Jun 09, 2004 9:07 am
by Grim...
Ah, the techincal revolution.
And here's me expecting the postman to deliver it :)

Posted: Wed Jun 09, 2004 9:09 am
by patrikG
I can PM it to you, if you like...

Posted: Wed Jun 09, 2004 9:50 am
by Grim...
:P

Posted: Wed Jun 09, 2004 10:26 am
by Saethyr
hehe, go ahead and get dessert THIS TIME! ;)

And I am thinking the 17 hour plane ride to Patrik's would spoil my appetite.