Your script is very insecure... you should not allow total access to your file system through a request like this... it could be abused to if not execute undesireable system commands, to at least get info from places on your filesystem that you had not intended
you can help with the security some by checking the string and altering it before printing this back out into your code.
if you could i would restrict your option to either a fixed list of images to call... or a fixed pattern...
look at the basename() function and some other file system functions
you could create an array( 'img1.png', 'img2.jpg' ) and use the in_array() function to make sure the requested image is allowed and simply set the image to default.gif is any other value is given
or you could remove all characters that may be bad... change all double dots '..' into single dots. perhaps use preg or ereg functions to capture only the file name at the end of the string, thereby skipping any bad option...
One option would be to write an 'image.php' script
look into php's image functions... image.php would return an image instead of an html document
<img src="image.php?file=foo.png" />
if would look something like this in pseudocode
[pseudocode]
look at request ?file='foo'
does that file exist?
is that file an image?
write the appropriate mime type using header() : Header ('Content-type: image/jpeg');
fopen the file()
fpassthru() the file there by making this php document return all the data in the other.
[/pseudocode]
these are just a bunch of thoughts to get you going... maybe none of them are what you are looking for