Jump to content

php image gallery help!


tm2000

Recommended Posts

Hi,

 

I have a great php gallery that I found courtesy of http://www.jkemppainen.com, but what I need to be abel to do is add the file name underneath each thumbnail. I'm a newbie to php, and cannot work out how to do this.

 

This is my demo site:

http://www.tygamarketing.com/smartgallery/index.php

 

Any help will be much appreciated!!

 

Thanks in advance!

 

Andy

Link to comment
https://forums.phpfreaks.com/topic/169233-php-image-gallery-help/
Share on other sites

The filename is obviously used in the <img src= attribute. Find this and echo it under your picture. I dont know your script but as an example:

// loop through database table of image files
while($row = $db->nrecord()) {
  print "<img src='images/".$row->filename."' />";
  // print the filename under image
  print "<br />".$row->filename;
}

Don't take this code and look for it in your script as it will be different. Just find the part that prints out the images.

I can't get it to work!

 

This is the script that I think needs changing:

it's php4 if that helps!!  See below:

 

<?php

function php_thumbnails($imagefolder,$thumbfolder,$lightbox)

    {

    //Get image and thumbnail folder from function

    $images = "portfolio/" . $imagefolder; //The folder that contains your images. This folder must contain ONLY ".jpg files"!

    $thumbnails = "portfolio/" . $thumbfolder; // the folder that contains all created thumbnails.

    //Load Images

//load images into an array and sort them alphabeticall:

$files = array();

if ($handle = opendir($images))

{

while (false !== ($file = readdir($handle)))

{

//Only do JPG's

if(eregi("((.jpeg|.jpg)$)", $file))

 

{

$files[] = array("name" => $file);

}

}

closedir($handle);

}

//Obtain a list of columns

 

foreach ($files as $key => $row)

{

$name[$key]  = $row['name'];

}

//Put images in order:

array_multisort($name, SORT_ASC, $files);

//set the GET variable name

$pic = $imagefolder;

//Thumbnails

//Recursively go trough the array of images and add thmubnails to the page:

foreach ($files as $file)

{

$addy = $_GET[$pic];

 

$string = $file['name'];

// Print the currently viewed thumbnail

 

if( $addy == $file['name'] AND $lightbox == "lb-off")

{

$name = $file['name'];

 

$splitname = explode (".", $name);

 

$pictitle = str_replace("_"," ",$splitname[0]);

 

echo("<img class=\"thumb_active\" src=\"" . $thumbnails . "/$splitname[0]_thumb.jpg\" alt=\"$pictitle\"> \n");

 

}

// Print thumbnails with link

 

else

 

{

 

// Check if thumbnail already created

 

$name = $file['name'];

 

$splitname = explode (".", $name);

 

$pictitle = str_replace("_"," ",$splitname[0]);

if( $lightbox == "lb-on")

{

$link = "<a rel=\"lightbox[" . $images . "]\" title=\"$splitname[0]\" href=\"" . $images . "/" . $name . "\">";

}

else

{

$link = "<a href=\"?" . $pic . "=" . $file['name'] . "\">";

}

 

if (file_exists("$thumbnails/$splitname[0]_thumb.jpg"))

 

{

 

// Load the thumbnail image

echo($link);

echo("<img class=\"thumb\" src=\"" . $thumbnails . "/$splitname[0]_thumb.jpg\" alt=\"$pictitle\"></a> \n");

 

}

 

else

{

 

// Create a thumbnail image

echo($link);

echo("<img class=\"thumb\" src=\"thumbnail.php?imagefolder=" . $images . "&thumbfolder=" . $thumbnails . "&name=" . $file['name'] . "&im=" . $images .  "/" . $file['name'] . "\" alt=\"$pictitle\"></a> \n");

 

}

 

}

}

reset($files);

}

?>

 

 

Thanks again Neil - but I'm still having trouble!

 

I added your line:

echo("<img class=\"thumb_active\" src=\"" . $thumbnails . "/$splitname[0]_thumb.jpg\" alt=\"$pictitle\"> \n<br />\n".$splitname[0]_thumb.jpg);

 

but it didn't work at all (just showed blank screen) - then, I amended your line, as I think maybe the quote marks were in the wrong place at the end? - so now i have:

 

echo("<img class=\"thumb_active\" src=\"" . $thumbnails . "/$splitname[0]_thumb.jpg\" alt=\"$pictitle\"> \n<br />\n.$splitname[0]_thumb.jpg");

 

but it's still not adding the filename below the thumbnail:

 

http://www.tygamarketing.com/smartgallery/index.php

 

 

Any ideas? Sorry to be a pain!! (I'm in the very early stages of learning php, so bear with me!)

If you get a blank screen you need to turn error reporting on. Add this at the top of your script.

ini_set('display_errors', 'on');

 

Looks like you have a few lines of image echos. Add the extra part to all of them or simply just add a random bit of text after the <img src tag to see if it prints out.

 

Also other bit of code should be

<?php
echo("<img class=\"thumb_active\" src=\"" . $thumbnails . "/$splitname[0]_thumb.jpg\" alt=\"$pictitle\"> \n<br />\n".$splitname[0]."_thumb.jpg");
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.