Skip to main content.
pictures.php3

Return to gallery page

<script language="php">
// Image Gallery by Tom Parker <palfrey@tevp.net>
// http://tevp.net
//
// Released under the GPL Version 2 (http://www.gnu.org/copyleft/gpl.html)

if (!isset($pictures)) {
    echo 
"Must have a value for 'pictures'";
    exit;
}

if (!isset(
$display)) {
    echo 
"Must have a value for 'display'";
    exit;
}

if (!isset(
$width))
    
$width=4;

if (!isset(
$keepaspect))
    
$keepaspect 1;

if (!isset(
$max))
    
$max 20;

if (!isset(
$imagewidth))
    
$imagewidth 75;

if (!isset(
$dirsep))
    
$dirsep "";

$start $_GET["start"];

if (!isset(
$start))
    
$start=0;

$sub_dir $_GET["sub_dir"];
$REQUEST_URI $HTTP_SERVER_VARS["REQUEST_URI"];
$sub_dir preg_replace("|\\\'|","'",$sub_dir);
#$sub_dir .= '/';
$whole_dir $pictures.$sub_dir.'/';
#print $whole_dir. " ".getcwd();

if (isset($header) && $header!="")
{
    
$my_dir $sub_dir==""?"/":$sub_dir;
    include 
$header;
}

//umask(002);
$old_path getcwd();
if (!
file_exists($whole_dir))
{
    if (
substr($sub_dir,0,1)=="/")
    {    
        
$sub_dir substr($sub_dir,1);
    }
    print 
"Can't find $sub_dir, redirecting you to the root folder<br>\n";
    
$whole_dir $pictures.'/';
    
$sub_dir "";
}
#print $whole_dir;
chdir($whole_dir);
$dir opendir('.');
if (!
file_exists("tn")) {
    
mkdir ("tn"0777);
    if (isset(
$www_user))
    {
        
chown("tn",$www_user);
    }
    if (isset(
$www_group))
    {
        
chgrp("tn",$www_group);
    }
}
if (
fileperms("tn")!=040777)
{
    print 
"Changed perms";
    
printf("%o",fileperms("tn"));
    
chmod("tn",040777);
    
printf("%o",fileperms("tn"));
}
$stack = array();
if (
substr($sub_dir,0,1)!='/')
{
    
$sub_dir "/".$sub_dir;
}
if (
$sub_dir!='/')
{
    print 
"<b>Current directory: ".str_replace("/"," -> ",substr($sub_dir,1))."</b><br />\n";
}
if (
$sub_dir!="/") {
    
$lower_dir $sub_dir;
    if ((
$pos strrpos($lower_dir,"/")))
        
$lower_dirsubstr($lower_dir,0,$pos);
    else
        
$lower_dir="";
    print 
"<a href=\"".preg_replace("/(.*)\/(.*)/","$2",$SCRIPT_FILENAME)."?sub_dir=".$lower_dir."\"><b>Go up a directory</b></a><br />\n";
}

$did_desc=0;
if (
file_exists("descriptions.txt")) {
    
$des file("descriptions.txt");
    for (
$i=0;$i<sizeof($des);$i++) {
        if (
strcmp(substr($des[$i],0,1),".")==0) {
            
$disp substr($des[$i],2);
            
$disp trim($disp);
            if (
strlen($disp)>0)
            {
                print 
"<b>".$disp."</b><br />";
                
$did_desc=1;
            }
            break;
        }
    }
    
//print $des[0];
}
print 
"";

$thumbs = array();
$thumb_dir opendir("./tn");
while ((
$file readdir($thumb_dir))!=false) {
    if (
$file!='.' && $file!='..' && $file[0]=='t' && $file[1] == 'n'// Only add thumbnails to the list
        
array_push($thumbs$file);
}


$subdirs = array();
while ((
$file readdir($dir))!=false) {
    if (
$file!='.' && $file!='..') {
        if (!
is_dir($file)) {
            
$tnname "tn/tn_".$file;
            if (
preg_match("/\.flv/i",$file))
                
$tnname substr($tnname,0,-3)."jpg";
            if (!
file_exists($tnname) || filemtime($tnname)< filemtime($file)) {
                if (
preg_match("/\.png/i",$file))
                    
$im ImageCreateFromPNG ($file);
                if (
preg_match("/\.jpg/i",$file))
                    
$im ImageCreateFromJPEG ($file);
                if (
$im)
                {
                    
$ratio = (ImageSY($im)/ImageSX($im))*$keepaspect;
                    if (
$ratio == 0)
                        
$ratio 1;
                    
//print $ratio;

                    
$tn ImageCreateTrueColor($imagewidth,$imagewidth*$ratio);
                    
ImageCopyResampled ($tn,$im,0,0,0,0,$imagewidth,$imagewidth*$ratio,ImageSX($im),ImageSY($im));
            
//        $fh = fopen("tn/tn_".$file,"w");
            //        fclose($fh);
            //        chown("tn/tn_".$file,"palfrey");
                    
if (preg_match("/\.png/i",$file))
                        
ImagePNG ($tn,$tnname);
                    if (
preg_match("/\.jpg/i",$file))
                        
ImageJPEG ($tn,$tnname);
                    print 
"tn/tn_".$file."<br>";
                }
            }
            if (
preg_match("/\.jpg/i",$file) || preg_match("/\.png/i",$file)|| preg_match("/\.flv/i",$file))
                
$stack[$file] = $tnname;
        }
        else {
            if (
is_dir($file) && $file!="tn"
                
array_push($subdirs$file);
        }
    }
}
closedir($dir);
usort($subdirs'strcasecmp');
//natcasesort($subdirs);
$trans = array(" "=>"%20","&"=>"%26","'"=>"%27");

$index 0;
while (list (
$key$file) = each($subdirs)) {
    if (
$index!=0)
        print 
" ".$dirsep." ";
    print 
"<a href=\"".strtr(preg_replace("/(.*)\/(.*)/","$2",$SCRIPT_FILENAME)."?sub_dir=".$sub_dir.(substr($sub_dir,strlen($sub_dir)-1)!='/'?'/':"").$file,$trans)."\">";
    print 
$file;
    print 
"</a>\n";
    
$index++;
}

natcasesort($stack);


#if ($start!=0 || ceil(sizeof($stack)/$max)>1)
#    print "<br />";

if ($start>0)
    print 
"<a href=\"".preg_replace("/(.*)\/(.*)/","$2",$SCRIPT_FILENAME)."?sub_dir=".strtr($sub_dir,$trans)."&amp;start=".($start-1)."\">&lt;&lt;</a> ";
if (
$start==&& ceil(sizeof($stack)/$max)>1)
    print 
"&lt;&lt; ";

if (
$start!=0) {
    for (
$i=0;$i<$start;$i++)
        print 
" <a href=\"".preg_replace("/(.*)\/(.*)/","$2",$SCRIPT_FILENAME)."?sub_dir=".strtr($sub_dir,$trans)."&amp;start=".$i."\">".($i+1)."</a>";
}

if (
$start!=|| ceil(sizeof($stack)/$max)>1)
    print 
" ".($start+1);

if (
ceil(sizeof($stack)/$max)-$start>0) {
    for (
$i=$start+1;$i<ceil(sizeof($stack)/$max);$i++)
        print 
" <a href=\"".preg_replace("/(.*)\/(.*)/","$2",$SCRIPT_FILENAME)."?sub_dir=".strtr($sub_dir,$trans)."&amp;start=".$i."\">".($i+1)."</a>";
}

if (
$start<ceil(sizeof($stack)/$max)-1)
    print 
" <a href=\"".preg_replace("/(.*)\/(.*)/","$2",$SCRIPT_FILENAME)."?sub_dir=".strtr($sub_dir,$trans)."&amp;start=".($start+1)."\">&gt;&gt;</a>";
if (
$start==ceil(sizeof($stack)/$max)-&& ceil(sizeof($stack)/$max)>1)
    print 
" &gt;&gt;";

print 
"<table align=\"center\"><tr>";
$count=0;
$total=0;
while (list (
$file$tnname) = each ($stack)) {
    
$remove basename($tnname);//"tn_".$file;
    
$temp = array();
    while (list(
$key$t_file) = each($thumbs))
        if (
$t_file != $removearray_push($temp,$t_file);
    
$thumbs $temp;

    if (
$total>=($start*$max) && $total<$max*($start+1)) {
        if (
$count == $width) {
            print 
"</tr>\n<tr>";
            
$count=0;
        }
        
$shortfile preg_replace("/\.jpg/i","",$file);
        
$shortfile preg_replace("/\.png/i","",$shortfile);
        
$shortfile preg_replace("/\.flv/i","",$shortfile);
        
        print 
"<td align=\"center\">";
        if (
preg_match("/\.avi/i",$file))
        {
            print 
"<a href=\"".strtr($pictures.$sub_dir.'/'.$file,$trans)."\">";
            print 
"<img src=\"".dirname($_SERVER["SCRIPT_NAME"])."/video.png\" alt=\"video\"><br/>".$shortfile."</a>";
        }
        else
        {
            print 
"<a href=\"".strtr($display."?image=".$sub_dir.'/'.$file,$trans);
            if (
$start!=0)
            {
                print 
"&amp;start=".$start."";
            }
            print 
"\"><img border=\"0\" src=\"";
            print 
strtr($whole_dir.$tnname."\"",$trans)." ".strtr("alt=\"".$shortfile,$trans);
            print 
"\"/><br/>";
            if (
preg_match("/\.flv/i",$file))
                print 
"(video) ";
            print 
$shortfile."</a>";
            print 
"</td>\n";
        }
        
$count++;
    }
    
$total++;
}

while (
$count<=$width) {
    print 
"<td>&nbsp;</td>";
    
$count++;
}

print 
"</tr></table>";
while (list (
$key$file) = each($thumbs)) {
    
unlink ("tn/".$file);
    print 
"wiped tn/".$file;
}

chdir($old_path);

function 
remove_item($named) {
    global 
$remove;
    if (
$named == $remove)
        return 
0;
    else
        return 
1;
}

</script>

Return to gallery page
  Page by Tom Parker <palf...@tevp.net>
This page was last updated on 13/11/2007 at 08:54:38 and has had a finite number of hits.
Listening to: The Dust Brothers - Single Serving Jack
Citizen! What number am I thinking of?
FOAF Get FirefoxValid XHTML 1.0!