View Full Version : Can I pass IMG attributes to a PHP page?

11-24-2007, 02:23 AM
Hi Folks,

I have a webpage that has some photos on it. They are displayed smaller than full size on most of the pages. I would like to make the images clickable to view them full size but not on a white page. I want them to be put into the same php generated pages the rest of the content uses.

I have had success doing this, but for each photo I put a static link that passes the information to the php file. For example:

<a href="picview.php?fname=images/myphoto.jpg&amp;caption=My Caption For This Picture">
<img src="images/myphoto.jpg" alt="a picture" title="My Caption For This Picture" />

Then on the php page side I use:

<img src="<?php echo $_GET['fname']; ?>" alt="Larger Image" />
<p><?php echo $_GET['caption']; ?></p>

Is there a more automatic way that will allow me to pull the filename and the title out of the <img></img> on the originating page and send it to the destination page?

11-24-2007, 02:30 AM
Not with PHP, but you should be able to with Javascript.

11-24-2007, 02:37 AM
You can create a simple text file that has a list of your photos.
The first field is a timestamp (or ID).

Something like this ... (call it "photos.db" )

1001|myphoto1.jpg|myphoto1_t.jpg|This is photo one's title|extra fields|
1002|myphoto2.jpg|myphoto2_t.jpg|This is photo two title|extra fields|
1003|myphoto3.jpg|myphoto3_t.jpg|This is photo three title|extra fields|
1004|myphoto4.jpg|myphoto4_t.jpg|This is photo four title|extra fields|
1005|myphoto5.jpg|myphoto5_t.jpg|This is photo five title|extra fields|

Then, your link is like this ... All of your thumbs could actually
be created by a PHP script that opens the text database and
creates the links/thumbs for you. But this is what 1 link looks like ...

<a href="picview.php?id=1001">
<img src="images/myphoto.jpg" />

Your PHP script is like this ("picview.php" ... simple example.)

#Read File List
$fp = fopen($database, "r");
$array1 = explode("\n", fread($fp, filesize($database)));
fclose ($fp);
<head><title>Page Title</title>
/* All of your CSS style stuff here */
body {
margin:0px auto;

$count = count($array1);
for($i = 1; $i < $count; $i++) {
list ($fid, $full, $thumb, $title, $extra) = split ('\|', $array1[$i]);
if($id == $fid){
// display full size image
<img src='$full' alt='$title' />


11-24-2007, 04:11 AM
Wow, thanks! I had thought of doing it that way but dismissed it as too convoluted. It'll take me some time to sift through the code so I understand it, but I do appreciate you posting it.