Forum Moderators: coopster

Message Too Old, No Replies

php image help

help with image that changes depending on variable in url

         

KrazyKid

3:47 am on Apr 25, 2005 (gmt 0)

10+ Year Member



i know almost nothing about php, but on my site i have a pics section, and when someone clicks on a thumbnail, it takes them to a seperate page with that image on it, and i'm tired of making a new page for each image, so what i need is something like this:

Thumbnails page:
<a href="pic.php?nameofpic"><img src="thumbnail.jpg"></a>

and then on the pic.php page:

<img src="name of image from url">

get it? thanks a lot in advance. :)

dreamcatcher

7:24 am on Apr 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi KrazyKid,

Easiest way to do it is to pass the file name in the url.

<a href="pic.php?img=picture.jpg"><img src="thumbnail.jpg"></a>

Then on your page, load the full size image via $_GET.

$img = $_GET['img'];

<img src="images/<?php echo $img;?>">

Hope that helps.

dc

KrazyKid

6:52 pm on Apr 25, 2005 (gmt 0)

10+ Year Member



thanks, works perfectly! one more thing though. say i also wanted a caption to show up under the picture, how would i also pass that in the url at the same time?

adb64

7:44 pm on Apr 25, 2005 (gmt 0)

10+ Year Member



Hi KrazyKid,

That can be done with an extra get parameter as follows:

<a href="pic.php?img=picture.jpg&amp;caption=Caption%20For%20Your%20Image"><img src="thumbnail.jpg"></a>

Use %20 for spaces in the caption as shown above.

Then on your page, load the full size image and caption via $_GET.

$img = $_GET['img'];
$caption = $_GET['caption'];

$info = getimagesize($img);

echo "<img src=\"$img\" ".$info[3]." alt=\"$caption\"><br>$caption";

This will also fill in the correct image dimension and popups the caption text when your visitor hovers over the image.

Regards,
Arjan