so hab da ne datei mit der man alle dateien aus nem ordner auslesen kann, da unser webspace kein dir-listing unterstützt
so, damit zeigt er aber die dateien nur mit namen an, nun weiß ich aber nicht wie man es so macht, dass er z.b. bilder direkt als bilder anzeigt und nicht den datei namen......
evl hat da ja jmd was, wäre nett
PHP-Code:
<?
class _file {
var $name;
var $size;
var $lastModified;
var $isDir;
var $description;
}
function getDescription($file, $descriptions) {
if(is_array($descriptions)) {
for($j=0;$j<count($descriptions);$j++) {
$condition = '';
for($i=strlen($descriptions[$j]);$i>0;$i--) {
if($descriptions[$j][$i] == '"') {
$condition = strtolower(substr($descriptions[$j], $i-strlen($descriptions[$j])+2));
break;
}
}
if(preg_match("=".$condition."=i", $file))
if(preg_match('="([[:alnum:]]+)(.*)"=i', $descriptions[$j], $regs))
return preg_replace('="=', '', $regs[0]);
}
}
}
function getFileImage($filename) {
// feel free to add more extensions,
// a list of the standart icons shipped with
// apache can be found in the /Apache/icons-folder
// .. where is it on linux machines?
$extension = '';
for($i=strlen($filename);$i>0;$i--) {
if($filename[$i] == '.') {
$extension = strtolower(substr($filename, $i-strlen($filename)));
break;
}
}
global $ALTTAG;
if(is_dir($filename)) {
$ALTTAG = '[DIR]';
return '/.icons/dir.gif';
} elseif($extension == '.gif' || $extension == '.png' || $extension == '.bmp' || $extension == '.jpg') {
$ALTTAG = '[IMG]';
return '/.icons/image2.gif';
} else if($extension == '.txt' || $extension == '.htm' || $extension == '.html' || $extension == '.css') {
$ALTTAG = '[TXT]';
return '/.icons/text.gif';
} elseif($extension == '.zip' || $extension == '.rar' || $extension == '.ace' || $extension == '.gz') {
$ALTTAG = '[ ]';
return '/.icons/compressed.gif';
} elseif($extension == '.avi' || $extension == '.mov' || $extension == '.mpg' || $extension == '.mpeg' || $extension == '.divx') {
$ALTTAG = '[VID]';
return '/.icons/movie.gif';
} elseif($extension == '.wav' || $extension == '.mp3' || $extension == '.snd') {
$ALTTAG = '[SND]';
return '/.icons/sound2.gif';
} elseif($extension == '.exe') {
$ALTTAG = '[ ]';
return '/.icons/binary.gif';
} else {
$ALTTAG = '[ ]';
return '/.icons/unknown.gif';
}
}
function shorten($file) {
if(strlen($file) > 23) {
$retval = substr($file,0,20) . '..>';
return $retval;
} else {
return $file;
}
}
function spaces($file, $n) {
$retvar = '';
if(strlen($file) >= $n-1)
return ' ';
else {
for($i=0;$i<($n-strlen($file));$i++)
$retval .= ' ';
return $retval;
}
}
function _filesize($size) {
if($size >= 1024) {
$retval = round($size/1024,1);
if(strlen($retval) > 3) $retval = round($size/1024);
return $retval.'k';
} elseif($size >= 1048576) {
$retval = round($size/1048576,1);
if(strlen($retval) > 3) $retval = round($size/1048576);
return $retval.'M';
} elseif($size >= 1073741824) {
$retval = round($size/1073741824,1);
if(strlen($retval) > 3) $retval = round($size/1073741824);
return $retval.'G';
} else
return $size;
}
function cmp ($a, $b) {
global $sortBy, $order;
if (strtolower($a->$sortBy) == strtolower($b->$sortBy)) return 0;
return (strtolower($a->$sortBy) > strtolower($b->$sortBy)) ? $order : ($order*-1);
}
if($showsource <> 1) {
$sortBy = '';
$order = '';
if(!isset($C)) $C = 'N';
if(!isset($O)) $O = 'A';
if($C == 'N') $sortBy = 'name';
if($C == 'M') $sortBy = 'lastModified';
if($C == 'S') $sortBy = 'size';
if($C == 'D') $sortBy = 'description';
if($O == 'A')
$order = 1;
else
$order = -1;
if(file_exists('.htaccess')) {
$htaccess = file('.htaccess');
$descriptions = array();
for($i=0;$i<count($htaccess);$i++) {
if(strtolower(substr($htaccess[$i], 0, 14)) == 'adddescription')
$descriptions[count($descriptions)] = trim($htaccess[$i]);
}
}
$files = Array();
$dummy = new _file;
$d = dir('.');
$i = 0;
while ($entry = $d->read()) {
if($entry != '.' && $entry != '..' && $entry != basename($PHP_SELF) && substr($entry,0,1) != '.') {
$dummy->name = $entry;
$dummy->size = filesize($entry) ? filesize($entry) : '-';
$dummy->lastModified = filemtime($entry);
$dummy->isDir = is_dir($entry);
$dummy->description = getDescription($entry, $descriptions);
$files[$i] = $dummy;
$i++;
}
}
$d->close();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>Index of <? $actpath = substr($PATH_INFO, 0, strlen($PATH_INFO)-strlen($PHP_SELF)+1); if($actpath != '') echo $actpath; else echo '/'; ?></TITLE>
</HEAD>
<BODY>
<H1>Index of <? $actpath = substr($PATH_INFO, 0, strlen($PATH_INFO)-strlen($PHP_SELF)+1); if($actpath != '') echo $actpath; else echo '/'; ?></H1>
<PRE><IMG SRC="/.icons/blank.gif" ALT=" "> <A HREF="?C=N&O=<? if($O == 'A') echo 'D'; else echo 'A'; ?>">Name</A> <A HREF="?C=M&O=<? if($O == 'A') echo 'D'; else echo 'A'; ?>">Last modified</A> <A HREF="?C=S&O=<? if($O == 'A') echo 'D'; else echo 'A'; ?>">Size</A> <A HREF="?C=D&O=<? if($O == 'A') echo 'D'; else echo 'A'; ?>">Description</A>
<HR WIDTH="99%">
<IMG SRC="/.icons/back.gif" ALT="[DIR]"> <A HREF="..">Parent Directory</A> <?=date('d-M-Y H:i', filemtime('..'))?> -
<?
usort($files, 'cmp');
for($i=0;$i<count($files);$i++) {
echo '<IMG SRC="'.getFileImage($files[$i]->name).'" ALT="'.$ALTTAG.'"> <A HREF="'.$files[$i]->name.'">'.shorten($files[$i]->name).'</A>'.spaces($files[$i]->name, 24).date('d-M-Y H:i', $files[$i]->lastModified).' '._filesize($files[$i]->size).spaces(_filesize($files[$i]->size), 6).$files[$i]->description."\n";
}
?>
<HR WIDTH='99%'></PRE>
<?
if($SERVER_SIGNATURE != '')
echo substr($SERVER_SIGNATURE,0,strlen($SERVER_SIGNATURE)-11).' (powered by <a href="'.$PHP_SELF.'?showsource=1">list.php</a>)</address>';
else
echo '<address>'.$SERVER_SOFTWARE.' Server (unknown version) at '.$HOSTNAME.' Port '.$SERVER_PORT.' (powered by <a href="'.$PHP_SELF.'?showsource=1">list.php</a>)</address>';
?>
</BODY></HTML>
<?
} else {
highlight_file($PHP_SELF);
}
?>?>
evl hat da ja jmd was, wäre nett
Kommentar