Forum Moderators: coopster
Say I have a directory with a bunch of images named "123456.jpg", "123457.jpg", etc.
And I have a link constructor that creates links with the image name as a variable (without the ".jpg") - like this:
http://www.example.com/imagedisplay.php?image=123456
I want to create a page that parses that variable, then places the image on a page - pulling in the image source from a location like this:
http://www.example.com/images/image123456.jpg
How can I do that?
Thanks in advance.
[edited by: dreamcatcher at 12:38 am (utc) on Dec. 15, 2009]
[edit reason] use example.com, thanks. [/edit]
$img_dir = '/images';
$img_prefix = 'image';
$ext = 'jpg';
//Avoid attempted hacks with a little filtering.
if (preg_match('/^\d+$/',$_GET['image'])) {
// or use is_numeric()
$src = '<img src="' . $img_dir . '/' .
$img_prefix . $_GET[image'] . '.' . $ext .
'">';
echo $src;
}
else { die("Hmm, not numeric.") }