simmsdk
Posts: 6
|
| Posted: 09/23/2004, 10:29 AM |
|
I wanted a gallery, where i could just dump all my images in a gallery dir on the server, and the thumbs in a thumbs dir, and the get all the images put in a nice gallery....
And since i am a newbee in php, and didnt find any suited example, i want to share it so that hopefully other newbees can get a nice gallery.
Make a label called "make_gallery" on you page, and in the before show event, put this code:
// gallery base dir. All galleries are located in this dir
// remeber trailing slash
$basedir = "gallery/";
// Thumbs dir. Must be inside gallery dir
// thumbs must have same name as image !!!
$thumbs = "thumbs";
// number of colums
$cols = 4;
// Where to look for files, which gallery
$gallery_sub = CCGetFromGet("gallery","");
$gallery = $basedir.$gallery_sub;
$i = 1;
$files = array();
$myDirectory = opendir("$gallery/$thumbs");
$html="<table width='760' align=\"center\" border ='0' cellpadding='5' cellspacing='0'><tr>";
while ($file = readdir($myDirectory)) {
if (($file != ".") && ($file != "..") && ($file != "index.php") && !(is_dir("$gallery/$file")) )
{
$files[] = $file;
if (is_int($i/$cols)) {
$html .= "<td><p align=\"center\"><a href=\"$gallery/$file\"><img src=\"$gallery/$thumbs/$file\" border=\"0\"></a></p></td></tr><tr>";
}
else
{
$html .= "<td><p align=\"center\"><a href=\"$gallery/$file\"><img src=\"$gallery/$thumbs/$file\" border=\"0\"></a></p></td>";
}
$i++;
}
}
$html .= "</tr></table>";
$make_gallery->SetValue($html);
closedir($myDirectory);
To call the script, use:
<name of page with you gallery label>.php?gallery=<gallery dir>
So if your gallery page is called "Gallery.php" and you gallery dir is called "test", you call it with:
gallery.php?gallery=test
Paths are :
gallery/test/
gallery/test/thumbs/
|