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
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.

Link to comment
Share on other sites

Thanks! I think I've found where it prints the thumbnail 0- this is the line I think that does it:

 

 

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

 

So do I just add what you sent underneath?

 

Link to comment
Share on other sites

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);

}

?>

 

 

Link to comment
Share on other sites

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!)

Link to comment
Share on other sites

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");
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.