Hallo alle zusammen,
ich habe hier unser PHP Dateianzeige Script.
Dies zeigt ebenfalls die Ordner an die im Verzeichnis vorhanden sind.
In die Ordner kann ich jedoch nicht rein, da muss irgendwas falsch sein, ich kann den Fehler leider nicht finden, kann mir bitte jemand helfen?
Es ist super wichtig, dass ich mit diesem script in Unterordner navigieren kann.
Für mich steht überhauptgarnicht fest wieso es nicht funktioniert.
Hoffe wir kriegen das schnell hin
Vielen Dank!
ich habe hier unser PHP Dateianzeige Script.
Dies zeigt ebenfalls die Ordner an die im Verzeichnis vorhanden sind.
In die Ordner kann ich jedoch nicht rein, da muss irgendwas falsch sein, ich kann den Fehler leider nicht finden, kann mir bitte jemand helfen?
Es ist super wichtig, dass ich mit diesem script in Unterordner navigieren kann.
Für mich steht überhauptgarnicht fest wieso es nicht funktioniert.
Hoffe wir kriegen das schnell hin
Vielen Dank!
PHP:
<?php
/*****************************************************************************\
* Configuration (adapt this section to your needs) *
\*****************************************************************************/
$su = false;
# paths
$rootDir = 'formulare';
$indexDir = 'Teiledienst';
$referer = $_SERVER['PHP_SELF'];
$printCwd = true;
# labels for tableheader
$hPic = ' ';
$hName = 'Name';
$hSize = 'Groesse';
$hType = 'Typ';
$hLastMod = 'Letzte Aenderung';
# show attributes
$showPic = true;
$showName = true; # must always be 'true'
$showSize = true;
$showType = false;
$showLastMod = true;
# pic-names
$picUp = '../gfx/folderup.gif';
$picFolder = '../gfx/folder.gif';
$picFile = '../gfx/file.gif';
# filter
$showFiles = '*';
$hideFiles = '.*,index*,*.php';
$showFolders = '*';
$hideFolders = '';
# mode
$xAction = 0;
$xFilename = 'dofile.php';
/*****************************************************************************\
* prepare variables *
\*****************************************************************************/
// Check Path Formats ---------------------------------------------------------
$rootDir = formatDir($rootDir,true,true);
$indexDir = formatDir($indexDir);
$referer = addLinker($referer);
// ----------------------------------------------------------------------------
// Handle (given) Directory ---------------------------------------------------
# initialize
$dir = $indexDir;
# make lokal variable from HTTP_GET_VARS
if(isset($_GET['dir']))
$dir = formatDir(rawParam('dir'));
# check given directory if it is valid/allowed
if( !isValidDir("$rootDir$dir") )
$dir = $indexDir;
# real path ($dir is just fake [relative to $rootDir] for display)
$ldir = formatDir("$rootDir$dir",true);
// ----------------------------------------------------------------------------
// Get Directory Content ------------------------------------------------------
$files = array();
$folders = array();
# unfiltered directory content
getDirContent( $ldir );
# filter (and sort) arrays
$files = filterArray( $files, $showFiles, $hideFiles );
$folders = filterArray( $folders, $showFolders, '.,..,'.$hideFolders );
// ----------------------------------------------------------------------------
/*****************************************************************************\
* Output (print table) *
\*****************************************************************************/
echo '<table cellspacing="3" class="expl">',"\n";
// print current directory ----------------------------------------------------
if($printCwd)
{
echo ' <tr class="path">',"\n";
echo ' <td colspan="'.($showPic+$showName+$showSize+$showType+$showLastMod).'"><em>/'.$dir.'</em></td>',"\n";
echo ' </tr>',"\n";
echo "<tr><td><div align=\"center\"><a href='formulare/Organisationshilfe/Start.htm'>ISO- und Organisationshilfe starten</a></td></tr>";
}
// ----------------------------------------------------------------------------
// draw tableheader -----------------------------------------------------------
echo ' <tr class="hExpl">',"\n";
if($showPic)
echo ' <td class="hPic"> '.$hPic.' </td>',"\n";
if($showName)
echo ' <td class="hName"> '.$hName.' </td>',"\n";
if($showSize)
echo ' <td class="hSize"> '.$hSize.' </td>',"\n";
if($showType)
echo ' <td class="hType"> '.$hType.' </td>',"\n";
if($showLastMod)
echo ' <td class="hLastMod"> '.$hLastMod.' </td>',"\n";
echo ' </tr>',"\n";
// ----------------------------------------------------------------------------
// handle up-button -----------------------------------------------------------
if( $su && (!$dir || (substr($dir,-2)=='..')) )
$up = formatDir($dir,true).'..';
else
$up = substr($dir,0,strrpos($dir,'/'));
if( $su || ($dir && ($up!==false)) )
{
echo ' <tr class="folder">',"\n";
if($showPic)
echo ' <td class="pic"><a href="'.$referer.'dir='.$up.'"><img src="'.$picUp.'" alt="up" /></a></td>',"\n";
if($showName)
echo ' <td class="name"><a href="'.$referer.'dir='.$up.'"><em>..</em></a></td>',"\n";
if($showSize)
echo ' <td class="size"> - </td>',"\n";
if($showType)
echo ' <td class="type"> dir </td>',"\n";
if($showLastMod)
echo ' <td class="lastmod"> - </td>',"\n";
echo ' </tr>',"\n";
}
// ----------------------------------------------------------------------------
// print directories ----------------------------------------------------------
foreach ($folders as $folder)
{
echo ' <tr class="folder">',"\n";
if($showPic)
echo ' <td class="pic"><a href="'.$referer.'dir='.formatDir($dir,true).$folder.'"><img src="'.$picFolder.'" alt="dir" /></a></td>',"\n";
if($showName)
echo ' <td class="name"><a href="'.$referer.'dir='.formatDir($dir,true).$folder.'"><em>'.$folder.'</em></a></td>',"\n";
if($showSize)
echo ' <td class="size"> - </td>',"\n";
if($showType)
echo ' <td class="type"> '.filetype("$ldir$folder").' </td>',"\n";
if($showLastMod)
echo ' <td class="lastmod"> - </td>',"\n";
echo ' </tr>',"\n";
}
// ----------------------------------------------------------------------------
// print files ----------------------------------------------------------------
foreach ($files as $file)
{
$type = filetype("$ldir$file"); // get 'type of file'
$modDate = filemtime("$ldir$file"); // get 'last modified date' of file
$modDate = date('Y-m-d',$modDate); // format date in ISO-Style
$size = filesize("$ldir$file"); // get 'size of file' in bytes
$size = ceil($size/1024); // convert from byte to kilobyte
$size = "$size kb"; // add unit
echo ' <tr class="file">',"\n";
if($showPic)
echo ' <td class="pic"><a href="'.makeLink("$ldir$file").'" target="_blank"><img src="'.$picFile.'" alt="file" /></a></td>',"\n";
if($showName)
echo ' <td class="name"><a href="'.makeLink("$ldir$file").'" target="_blank">'.$file.'</a></td>',"\n";
if($showSize)
echo ' <td class="size"> '.$size.' </td>',"\n";
if($showType)
echo ' <td class="type"> '.$type.' </td>',"\n";
if($showLastMod)
echo ' <td class="lastmod"> '.$modDate.' </td>',"\n";
echo ' </tr>',"\n";
}
// ----------------------------------------------------------------------------
echo '</table>',"\n";
/*****************************************************************************\
* Functions *
\*****************************************************************************/
// ----------------------------------------------------------------------------
// getDirContent() fills, filter and sort Arrays of files and folders
function getDirContent($dir)
{
global $files, $folders;
# fill arrays
$handle = @opendir($dir);
while( $file = readdir($handle) ) {
if( is_dir("$dir/$file") )
$folders[] = $file;
elseif( is_file("$dir/$file") )
$files[] = $file;
}
@closedir($handle);
}
// ----------------------------------------------------------------------------
// addLinker() adds '?' or '&' to the referer
function addLinker($referer)
{
// assume that last char is not '?' or '&'
return strchr($referer,'?') ? "$referer&" : "$referer?";
}
// ----------------------------------------------------------------------------
// formatDir() skip trailing and leading "/" in given $dir-string
// add
function formatDir($dir, $trailing=false, $leading=false)
{
$dir = trim($dir,' /');
if( $trailing && $dir )
$dir = "$dir/";
if( $leading ) #&& ($dir[0]!='/') )
$dir = "./$dir";
return $dir;
}
// ----------------------------------------------------------------------------
// filterArray() make regular expression from $filter-string
function filterArray( $array, $allow, $hide )
{
$allow = makeRegex($allow);
$hide = makeRegex($hide);
$tmp = array();
foreach( $array as $val )
if( ereg($allow,$val) && !ereg($hide,$val) )
$tmp[] = $val;
natcasesort( $tmp );
return $tmp;
}
// ----------------------------------------------------------------------------
// makeRegex() make regular expression from $filter-string
function makeRegex( $filter )
{
$regex = str_replace('.', '\.', $filter);
$regex = str_replace('*', '.+', $regex);
$regex = str_replace(',', '$|^', $regex);
return "^$regex$";
}
// ----------------------------------------------------------------------------
// isValidDir() return true if directory is valid/allowed
function isValidDir($dir)
{
global $su;
$strErr = "<p>Requested Directory Not Found</p>\n";
$strErr .= "\n</body>\n</html>"; #close open tags
// check if folder exists (when manipulated manually)
is_dir($dir) or die($strErr);
// prevent cd with relative path '../'
return $su ? true : !(strpos($dir,'..')!==false);
}
// ----------------------------------------------------------------------------
// rawParam()
function rawParam( $param )
{
return ini_get('magic_quotes_gpc') ? stripslashes($_GET[$param]) : $_GET[$param];
}
// ----------------------------------------------------------------------------
// makeLink() return target of click
function makeLink( $target )
{
global $xAction, $xFilename;
return $xAction ? "$xFilename?file=$target" : $target;
}
?>