CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Simple Image Gallery from image dir

Print topic Send  topic

Author Message
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.:-D

  
  
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/  

View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.