# imgdir.php ver 0.09 # # browse image directory function # # generates html table with images and # links to the actual filenames # # jan/2001 - mauricio portasio - [email protected] # pls keep this header block when using these funcs # no support is provided, but please send # suggestions or bug reports. # tested on: # Apache/1.3.14 (Win98 4.1) PHP/4.04 # Apache/1.3.12 (Unix) PHP/4.0.3pl1 # load html tag definitions # require ("htmldefs.inc"); # suggestion: move defines below to htmldefs.inc and uncomment line above define ("LINE_BREAK", "
"); define ("TABLE_START", ""); define ("TABLE_END", "
"); define ("ROW_START", " "); define ("ROW_END", " "); define ("COL_START", " "); define ("COL_END", ""); define ("IMG_START", ""); define ("IMG_WIDTH", " width="); define ("IMG_HEIGHT", " height="); define ("A_START", ''); define ("A_END", ""); # dirToArray # # directory to array extractor # $browsedir (string - path name) # $extentions (array - extensions to be listed) function dirToArray ($browsedir, $extensions) { $MAXDIRSIZE = 20000; $nextensions = sizeof ($extensions); $idirectory = 0; $directory = dir ($browsedir); while ($entry = $directory->read()) { for ($i=1; $i<=$nextensions; $i++) { $compare = stristr ($entry, $extensions[$i]); if (strlen($compare) == strlen($extensions[$i])) { $adirectory[++$idirectory] = $entry; break; } } } $directory->close(); return $adirectory; } # showDir # # show table with images and links # $browsedir (string - path name) # $adirectory (array - filenames w/o path) function showDir ($adirectory) { global $browsedir; # change layout options here - should be parameters actually... $maxcols = 3; $imagemaxwidth = 160; $imagemaxheight = 120; $imagemaxratio = $imagemaxwidth / $imagemaxheight; $ndirectory = sizeof ($adirectory); echo (TABLE_START); for ($i=0; $i<=$ndirectory;) { #echo (ROW_START); for ($icols=1; $icols<=$maxcols; $icols++) { #echo (COL_START); $imagefilename = $adirectory[++$i]; if (strlen($imagefilename)>0) { $imagepath = $browsedir."/".$imagefilename; $imagesize = GetImageSize ($imagepath); if ($imagesize) { $imagewidth = $imagesize[0]; $imageheight = $imagesize[1]; $imageratio = $imagewidth / $imageheight; if ($imageratio > $imagemaxratio) { $imageoutputwidth = $imagemaxwidth; $imageoutputheight = ceil ($imagemaxwidth/$imagewidth*$imageheight); } else if ($imageratio < $imagemaxratio) { $imageoutputheight = $imagemaxheight; $imageoutputwidth = ceil ($imagemaxheight/$imageheight*$imagewidth); } else { $imageoutputwidth = $imagemaxwidth; $imageoutputheight = $imagemaxheight; } echo (A_START.$imagepath.A_CLOSE); echo (IMG_START.$imagepath.IMG_WIDTH.$imageoutputwidth.IMG_HEIGHT.$imageoutputheight.IMG_END); #echo (LINE_BREAK.$adirectory[$i]); echo (A_END); } #echo (COL_END); } } #echo (ROW_END); } #echo (TABLE_END); } # main - test # list allowed extensions here $extensions[1] = "jpeg"; $extensions[2] = "jpg"; $extensions[3] = "gif"; $extensions[4] = "png"; $extensions[5] = "bmp"; # directory to be browsed $browsedir = "./"; showDir ( dirToArray ($browsedir, $extensions) ); ?> Index of ".$pfath_info["dirname"]."\r\n"; echo "\r\n"; echo "\t\r\n\t\r\n\t\r\n"; echo "\r\n\r\n"; echo "\r\n\r\n"; echo "\t\r\n"; echo "\t\r\n"; echo "\t\r\n"; echo "\r\n"; $n = sizeof($files); for($i=0;$i<$n;$i++) { echo "\t\r\n"; echo "\t\r\n"; echo "\t\r\n"; echo "\r\n"; } echo "
"; if($C!="N") echo ""; else echo ""; echo "Name"; if($C!="M") echo ""; else echo ""; echo "Last modified"; if($C!="S") echo ""; else echo ""; echo "Size

Parent Directory
"; if(substr($files[$i],-1)=="/") { echo "�".$files[$i].""; $s="-"; $e=""; } else { echo " ".$files[$i]; $s=filesize($files[$i]); $e=""; if ($s>=1024) { $s/=1024; $e="K"; if ($s>=1024) { $s/=1024; $e="M"; if ($s>=1024) { $s/=1024; $e="G"; } } $s=round($s*10)/10; } } echo "".date("d-M-Y H:i", filemtime($files[$i]))."".$s.$e."
\r\n"; ?>