Forum Moderators: coopster
Heres the script:
<?php
// snapshot gallery
$cwd = getcwd(); // get current working directory
// create snapshot sub navigation
// search current working directory for snapshot folders
$handle = opendir("$cwd");
$folders = array();
$i = 0;
while (($directory = readdir($handle))!= false) {
// read snapshot folders.
if (
(is_dir($directory)) and // make sure $directory is a folder, not a file
($directory!= ".") and// don't read hidden folders
($directory!= "..")
) {
$folders[$i] = "$directory"; // add folder name to array
$i++;
}
}
sort($folders); // sort folder names alphabetically
reset($folders); //set array to read from the start after sorting
// create links with folder names. Format into list.
$snap_sub_nav = "
<div id=\"snapshot-nav\" style=\"text-transform: capitalize;\">
<p>Choose a Gallery »</p>
";
foreach($folders as $value) {
$snap_sub_nav .= "›
<a href=\"index.php?dir=".urlencode("$value")."\" title=\"View Gallery\">$value</a><br>
";
}
$snap_sub_nav .= "
</div>
";
// end snapshot sub navigation
// set snapshot directory
if ((isset($_GET["dir"])) and (is_dir($cwd."/".$_GET["dir"]))) {
$dir = strip_tags(urldecode($_GET["dir"])); // directory selected for viewing
} else {
$dir = ""; // no directory chosen - display snapshot home page.
}
// Read blurb.html in snapshot directory.
if (file_exists($cwd."/".$dir."/blurb.html")) {
$blurb_file = $cwd."/".$dir."/blurb.html"; //create full path to blurb.html
$blurb_handle = fopen($blurb_file,"r"); // open blurb.html for reading
$blurb = fread($blurb_handle, filesize($blurb_file)); // read blurb.html
fclose($blurb_handle); // close file
}
// build page content
// thumbnails or images
if ($dir!= "") { // snapshot directory is selected - display thumbnails
// get imaage file names
$img_handle = opendir($cwd."/".$dir."/thumbnails/");
$img_list = array();
$i = 0;
while (($img = readdir($img_handle))!= false) {
if (
(!is_dir($img)) && // don't read folders
(strpos("$img",".")!= 0) &&// don't read hidden files
((stristr($img,".jpg")==true) or (stristr($img,".gif")==true))
) {
$img_list[$i] = $img; // add image to image array
$i++;
}
} // end while
// check for pic
if (!isset($_GET["pic"])) { // no pic chosen, show thumbnails
$thumb_col = 0;
foreach($img_list as $key => $value) {
$size = @getimagesize($cwd."/".$dir."/thumbnails/$value"); // get image size
$thumbs .= "
<td align=\"center\" valign=\"middle\">
<a href=\"index.php?dir=".urlencode($dir)."&pic=".urlencode($key)."\" title=$vaule>
<img src=\"$dir"."/thumbnails/$value\" {$size[3]} border=\"0\" alt=$vaule>
</a>
</td>
";
if ($thumb_col >=3) { // break thumbs table into 4 column rows
$thumbs .= "\n</tr>\n<tr>";
$thumb_col = 0;
} else {
$thumb_col++;
}
}
// format thumbnail table
$thumbs_table = "
<table cellpadding=\"4\" cellspacing=\"0\" width=\"100%\" align=\"left\">
<tr align=\"center\" valign=\"middle\">
$thumbs
</tr>
</table>
";
} else {// pic chosen, display with previous/next/back links
$pic = strip_tags(urldecode($_GET["pic"]));
$links = "<p>";// begin next/prev links
//display pic with prev and next links
if ($pic > 0) { //set prev link
$links .= "
<a href=\"index.php?dir=".urlencode($dir)."&pic=".urlencode(($pic-1))."\" title=Previous Photo>
Previous</a> ¦
";
}
// back to thumbnails link
$links .= "<a href=\"index.php?dir=".urlencode($dir)."\" title=Back to Contact Sheet>
Back</a> ¦ <a href=\"/buy.php?dir=".urlencode($dir)."&pic=".urlencode(($pic))."\" title=Buy a Print of this photo>Buy Prints</a>";
if ($pic < (count($img_list)-1)) {
$links .= "
¦ <a href=\"index.php?dir=".urlencode($dir)."&pic=".urlencode(($pic+1))."\" title=Next Photo>
Next</a>";
}
$links .= "</p>"; // close next/prev links
// get pic size
$size = @getimagesize($cwd."/".$dir."/".$img_list["$pic"]);
$image .= "
$links
<p>Image Reference: ".$img_list["$pic"]."</p>
<br><img src=\"$dir/".$img_list["$pic"]."\" {$size[3]} border=\"0\" alt=$pic>
";
} // end if pic
}// end if dir
// determine page display
if (($dir!= "") and ($pic!="")) { //display image with links
echo "<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=225 align=left valign=top style=padding:5px;>"; //start of table
echo $blurb;
echo "<p>Quick Links »</p>
› <a href=\"/buy.php?dir=".urlencode($dir)."&pic=".urlencode(($pic))."\" title=Buy a Print of this photo>Buy Prints</a><br>
› <a href=\"/contact.html\">Contact Us</a><br>
› <a href=\"/images/galleries/index.php\">Back to Galleries</a><br>
</td><td align=right valign=top>"; //end of blurb td
echo $image;
echo "</td></tr></table>"; //end of table
} else if (($dir!= "") and ($pic =="")) { // display thumbnails of chosen snapshot folder
echo "<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=225 align=left valign=top style=padding:5px;>"; //start of table
echo $blurb;
echo "<p>Quick Links »</p>
› <a href=\"/contact.html\">Contact Us</a><br>
› <a href=\"/images/galleries/index.php\">Back to Galleries</a><br></td><td align=right valign=top>"; //end of blurb td
echo $thumbs_table;
echo " </td></tr></table>"; //end of table
} else { // display snapshot gallery home
echo "<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=225 align=left valign=top style=padding:5px;>"; //start of table
echo $blurb;
echo "<p>Quick Links »</p>
› <a href=\"/buy.php\" title=Buy a Print of this photo>Buy Prints</a><br>
› <a href=\"/contact.html\">Contact Us</a><br>
</td><td align=left valign=top>"; //end of blurb td
echo $snap_sub_nav;
echo "</td></tr></table>"; //end of table
}
?>
What it does, it search through folders that are in the folder its in, eg
Say the script is in a folder called images, it will search the folder for other folders and display them as a menu.
It will then create a contact sheet from thumbnails of each folder it finds.
Those thumbnails link to the images, and so on.
I want the script to ask for a user name and password and access password protected folders and index them. How can i do this?
Any help will do!
Ps feel free to use the script!
You could develop an authentication system and make that the requirement for each directory you want protected. Check for a valid userid and password, and if they don't meet the criteria, give them a message or redirect them to a login page.
your best chances are to either
1. Learn some basic PHP (your thing seems fairly simple)
or
2. Hire someone to do it for you
you probably won't find to many people to do it for free
(i would usually help, but i'm on vacation -yes i brought my laptop but what kind of geek would i be if i didn't)