# TE Directory Listing Script % 08/10/2001 Jerrett Taylor v1.4.1
# www.tescripts.net
/// Customization
// no directory BELOW this will be viewable
$title=''; // title of table, leave blank to use default
$showfilenames=0; // showfilenames .. if disabled and file has no description, name will be used.
$openwindow=1; // open in popup, 1 = true, 0 = false
$showimagesize=1; // show image height/width
$thumbnails=0; // show image thumbnails
$browse=1; // allow subdirectory browsing
$filetypes='jpg|gif|png'; // allowable filetypes, seperate with | (to list all files, use '.')
$fadethumbs=1; // apply fade effect to thumbnail mouseovers
$rootdir='.'; // directory to show images in, '.' will show images in the same dir as the file.
$os="NIX"; // Operating System, set as "WIN" if you are using Windows, otherwise leave as "NIX"
// Subdirectory browsing is disabled on windows machines.
// modify look/layout
$tdcolor="f1f1f1"; // main td color
$tdovercolor="fffff1"; // td mouseover color
$bordercolor="000000"; // table border color
$textcolor="000000"; // td text color
$tablewidth='500'; // width of the table.. you might want to change this to fit your layout better.
// name of imagemagick convert program (and path if required) .. default is 'convert'
// this is used for thumbnails.. if you don't have it, get it installed!
// comment this out if you don't want to use it
// you may have to use the full path
$imconvert='/usr/local/bin/convert';
// don't have imagemagick? you can still manually create thumbnails, they should be 80x50 images,
// with the filename image_tedlsthumb.jpg .. they should ALWAYS be jpg. (image.gif , thumbnail would be image_tedlsthumb.jpg)
////
// To use file descriptions, save a plain text file named FILENAME.EXT.desc , with the description in it
// for example, to have a description for beach.jpg, you would save your description file as beach.jpg.desc
// .desc files will NOT be listed by this script, even if you have $filetypes set to '.'
////////////////////////
// SCRIPT BEGINS HERE
function cleanData($data) {
// removes characters that break things ;]
$data = ereg_replace("-","",$data);
$data = ereg_replace(" ","",$data);
$data = ereg_replace('\.','',$data);
$data = ereg_replace('\'','',$data);
return $data;
}
if ($x == "view") {
echo '
Viewing Image
[ Close Window ]

';
exit();
}
$showdir = ereg_replace("\.\./","",$showdir);
if ($showdir) { $listdir = $rootdir.ereg_replace("\./","",$showdir); } else { $listdir = $rootdir; }
$handle=@opendir($listdir);
if (!$handle) { echo "no directory ('.$listdir.'), dying."; exit(); }
while (($file = readdir($handle))!==false) {
$filearray[count($filearray)] = $file;
}
asort($filearray); closedir($handle);
// count files
$filecount=0;
foreach ($filearray as $file) {
$name = split("\.",$file);
if ((eregi($filetypes,$name[count($name)-1]) == true) && (eregi("tedlsthumb",$file) == false)) { $filecount++; }
}
// deal with title
if (!$title) $title = 'Listing all available images in '.$listdir;
$title.=' ('.$filecount.' files)';
echo '
'.$title.' | ';
// loop through all files, build and sort array
if ($os == "WIN") {
$tmp = split('/',$SCRIPT_NAME);
$docroot = @ereg_replace($tmp[count($tmp)-1],'',$SCRIPT_NAME);
} else {
$tmp = split('/',$SCRIPT_FILENAME);
$docroot = @ereg_replace($tmp[count($tmp)-1],'',$SCRIPT_FILENAME);
}
@chdir($docroot.$listdir);
// subdirectory browsing
if (($browse==1) && ($os != "WIN")) {
if ($showdir) {
$updir = split("/",$showdir);
$tmp = count($updir)-1;
$i=0;
while ($i<$tmp) {
$back.=$updir[$i].'/';
$i++;
}
$back = substr($back,0,strlen($back)-1);
echo '« parent directory | ';
}
foreach ($filearray as $file) {
if (is_dir($file) && $file != '.' && $file != '..') {
// count files
$tmphandle=@opendir($file);
$subfilecount=0;
while (($tmpfile = readdir($tmphandle))!==false) {
$tmpname = split("\.",$tmpfile);
if ((eregi($filetypes,$tmpname[count($tmpname)-1]) == true) && (eregi("tedlsthumb",$tmpfile) == false)) {
$subfilecount++; }
}
closedir($tmphandle);
echo ''.$file.' ('.$subfilecount.' files) | ';
}
}
}
// loop all files, and filter file types
foreach ($filearray as $file) {
$name = split("\.",$file);
if (eregi($filetypes,$name[count($name)-1]) == true) {
// get filesize and translate to human readable size
$file_size = filesize($file);
if ($file_size >= 1073741824) {
$file_size = round($file_size / 1073741824 * 100) / 100 . "g";
} elseif ($file_size >= 1048576) {
$file_size = round($file_size / 1048576 * 100) / 100 . "m";
} elseif ($file_size >= 1024) {
$file_size = round($file_size / 1024 * 100) / 100 . "k";
} else {
$file_size = $file_size . "b";
}
unset($fileinfo);
if (file_exists($file.'.desc')) {
if ($showfilenames == 1) $fileinfo = ''.$file.' ';
$fdesc = fopen ($file.'.desc',r);
$fileinfo .= fread ($fdesc, filesize ($file.'.desc'));
fclose ($fdesc);
} else {
$fileinfo = ''.$file.' ';
}
if ($size = @getimagesize($file)) {
$nw = $size[0] + 23;
$nh = $size[1] + 40;
}
if ($showimagesize == 1) {
$imagesize = $size[0].'x'.$size[1];
}
if ($file != '.' && $file != '..' && !ereg('.desc',$file) && !ereg('tedlsthumb',$file)) {
echo '';
// thumbnail handling
if ($thumbnails==1) {
if ($imconvert && !file_exists($name[0].'_tedlsthumb.jpg')) exec($imconvert.' -quality 70 -geometry 80X50 '.$docroot.$listdir.'/'.$file.' '.$docroot.$listdir.'/'.$name[0].'_tedlsthumb.jpg');
if (file_exists($name[0].'_tedlsthumb.jpg')) {
$thumbnailimg = $listdir.'/'.$name[0].'_tedlsthumb.jpg';
} else { $thumbnailimg = $listdir.'/'.$file; }
// fade effect toggle
if ($fadethumbs == 1) {
echo ' | ';
} else { echo ' | '; }
}
$tdwidth = $tablewidth - 130;
echo ''.$file_size.' '.$name[count($name)-1].' '.$imagesize.' |
'.$fileinfo.' |
';
}
}
}
echo '
Powered by TEDLS |
|
';
?>