I dont know if this forum is a good place to post this sort of thing, but I am registered here so I thought I would. I created this semi-generic script to allow users to browse a folder of photos, with subfolders (the albums in this case).
You must be using PHP 4.1 for this to work.
To install, installs this script as pics.php in your document root, then in your doc root create a folder (referred to as $basedir) to hold your subfolders or albums. You must then modify the variable $basedir to be the actual path to the folder your created to hold your albums. Then just drop pictures in your albums!
When you call this page initially you need to pass in pics.php?album=none to display the list of albums in $basedir.
No, this isnt the cleanest code it took only about 20 mins and needs more work but I dont have time. Anyway here it is, feel free to modify and repost.
Code: Select all
<?PHP
$basedir = "/Library/WebServer/Documents/photo/";
$album = $_REQUESTї'album'];
if ($_REQUESTї'album'] == 'none')
{
printf("<html><head><style>");
printf("body {background:#000000;
color:#ffffff;
font-family:verdana;
font-weight:bold;
font-size:10pt;}
a {text-decoration:none;
font-family:verdana;
font-size:9pt;
color:#ff0000;}</style></head><body>");
printf("<center>Choose a Photo Album<br>");
if ($fhandle = opendir($basedir))
{
while (false !== ($file = readdir($fhandle)))
{ $filepath = sprintf("%s%s", $basedir, $file);
if (is_dir($filepath)&&($file != '.')&&($file !='..'))
{
printf("<a href='pics.php?album=%s'>%s</a>", $file, $file);
printf("<br>");
}
}
closedir($fhandle);
}
}
else
{
$dir = sprintf("%s%s/",$basedir, $album);
$pic_num = $_REQUESTї'pic_num'];
if ($pic_num == '')
{
$pic_num = 0;
}
$pic_counter = 0;
if ($handle = opendir($dir))
{
while (false !== ($file = readdir($handle)))
{
if (($file != '.')&&($file != '..')&&($file != '.DS_Store'))
{
$pic_counter++;
//printf($pic_counter);
}
}
closedir($handle);
}
else {
printf("Couldnt Open Directory");
}
if ($pic_counter == 0)
{
printf("No Pictures To Display");
}
if($pic_num == 0)
{$prev_pic = $pic_counter-1;}
else
{$prev_pic = $pic_num-1;}
if($pic_num == $pic_counter-1)
{$next_pic = 0;}
else
{$next_pic = $pic_num+1;}
$sec_pic_counter = 0;
if ($sechandle = opendir($dir))
{
while(false !== ($file = readdir($sechandle)))
{
if (($file != '.')&&($file != '..')&&($file != '.DS_Store'))
{
if ($pic_num == $sec_pic_counter)
{
printf("<html><head><style>
body { background:#000000;
font-family:verdana;
font-size:8pt;
color:#ffffff;}
a { font-family:verdana;
text-decoration:none;
font-size:11pt;
color:#ff0000;
}
</style>
<script language=JavaScript>
<!--
var message='Dont Steal!';
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}
function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function('alert(message);return false');
// -->
</script>
</head>
<body>
");
printf("<center>");
printf("Displaying Picture: %s", $file);
printf("<BR>");
printf("<table><tr>");
printf("<td align=left><a href='/pics.php?pic_num=%s&album=%s'>Next Pic >></a></td>", $next_pic, $album);
printf("<td width=250 align=center><a href='/pics.php?album=none'>Back To Albums List</a></td>");
printf("<td align=right><a href='/pics.php?pic_num=%s&album=%s'><< Previous Pic</a></td>", $prev_pic, $album);
printf("</td></tr></table>");
printf("<br>");
printf("<img src='/Photo/%s/%s' border=2>", $album, $file);
printf("</center>");
}
$sec_pic_counter++;
}
}
closedir($sechandle);
}
}
?>