i wrote file explrer just displays directories but doesnt shows file info pls help me
CODE
<?
function ContentsOfDir($path)
{
$path = realpath($path); #create real path
$dirhandle = @opendir($path); #create directory class
$res=array();//aj-----
$count = 0;
$dirs="";
$files="";
#check every item in the directory
//while( false !== @($item = $dirhandle->read()) )
while (false !== @($item = readdir($dirhandle)))
{
#exlcude forbidden files/dirs
if( $item != '.' AND $item != '..' )
{
#check if dir or file
if( is_dir($path.'/'.$item) )
{
#check if its not banned
//if(!isBannedDir($path.'/'.$item)){
$dirs[] = $item;
}
}
elseif( is_file($path.'/'.$item) )
{
$files[] = $item;
$dirs[] = $item;
}
$count++;
}
//$dirhandle->close();
if( is_array($dirs) )
{
usort($dirs, 'strnatcmp');
}
if( is_array($files) )
{
usort($files, 'strnatcmp');
}
#create result array
$res['items'] = $count;
$res['dirs'] = $dirs;
$res['files'] = $files;
return $res;
}
function ItemsInDir($dir)
{
$res = ContentsOfDir($dir);
if( is_array($res['files']) )
{
$items = count($res['files']);
}
else
{
$items = 0;
}
if( is_array($res['dirs']) )
{
for( $i=0; $i < count($res['dirs']); $i++ )
{
$items = $items + ItemsInDir($dir.'/'.$res['dirs'][$i]);
}
}
return $items;
}
function ExtractExt($filename)
{
if(($dotpos = strrpos($filename, '.')) === false)
{
return false;
}
else
{
return substr($filename, $dotpos+1);
}
}
function FileDescriptionGen($filename)
{
$ext = strtolower(ExtractExt($filename));
if($ext == 'png' OR $ext == 'gif' OR $ext == 'jpg' OR $ext == 'psp' OR $ext == 'bmp' OR $ext == 'ai' OR $ext == 'tiff')
{
$res['picfilename'] = 'pic.gif';
$res['description'] = strtoupper($ext).' Image/Picture';
}
elseif($ext == 'html' OR $ext == 'htm')
{
$res['picfilename'] = 'doc.gif';
$res['description'] = 'Webpage';
}
elseif($ext == 'css')
{
$res['picfilename'] = 'txt.gif';
$res['description'] = 'Stylesheet';
}
elseif($ext == 'doc' OR $ext == 'pdf')
{
$res['picfilename'] = 'doc.gif';
$res['description'] = 'Document';
}
elseif($ext == 'php' OR $ext == 'php3')
{
$res['picfilename'] = 'php.gif';
$res['description'] = 'PHP Script';
}
elseif($ext == 'js')
{
$res['picfilename'] = 'txt.gif';
$res['description'] = 'Javascript';
}
elseif($ext == 'swf')
{
$res['picfilename'] = 'pic.gif';
$res['description'] = 'Flash file';
}
elseif($ext == 'txt')
{
$res['picfilename'] = 'txt.gif';
$res['description'] = 'Textfile';
}
elseif($ext == 'avi' OR $ext == 'mov' OR $ext == 'mpg' OR $ext == 'rm')
{
$res['picfilename'] = 'mov.gif';
$res['description'] = 'Video file';
}
elseif($ext == 'mp3' OR $ext == 'wav' OR $ext == 'ogg')
{
$res['picfilename'] = 'muz.gif';
$res['description'] = 'Music file';
}
elseif($ext == 'zip' OR $ext == 'rar' OR $ext == 'cab' OR $ext == 'b2z')
{
$res['picfilename'] = 'zip.gif';
$res['description'] = 'Compressed file';
}
elseif($ext == 'exe' OR $ext == 'bat')
{
$res['picfilename'] = 'exe.gif';
$res['description'] = 'Application';
}
else
{
$res['picfilename'] = 'enz.gif';
$res['description'] = 'File';
}
return $res;
}
#execute Script
//$phpself = $_SERVER['PHP_SELF'];
$dir = "e:/";
$userroot = "root";
$fulldir = ($dir);
//$res=ItemsInDir('PHP');
?>
<!------------javascript-------------->
<script type="text/javascript">
function open_dir(path)
{
document.forms[0].path.value = path;
document.forms[0].target = "_self";
document.forms[0].submit();
}
//$res=ItemsInDir('PHP');
</script>
<?
/*
$userroot='';
//$fulldir='';
echo '<form method="post" target="_self">';
echo '<input type="hidden" name="path" value="'.$dir.'">';
if( substr($fulldir, 0, strlen($userroot)) != $userroot)
{
#dir is lower than the root dir, show error
echo '<div style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; margin-top: 5px; margin-left: 5px;">Permission denied to access this directory. Contact system administrator to set access to this directory</div>';
}
elseif( !is_dir($fulldir) )
{
echo '<div style="font-family: Arial, Helvetica, sans-serif; font-size: 10pt; margin-top: 5px; margin-left: 5px;"><font color=red>**The requested directory does not exist. Contact system administrator to set access to your home directory. </font></div>';
}
else
{
echo '<table cellpadding="0" cellspacing="0" style="font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 8pt;" width="100%">
<tr>
<td style="width: 20px;"></td>
<td style="width: 175px;"></td>
<td style="width: 45px;"></td>
<td style="width: 70px;"></td>
<td style="width: 70px;"></td>
</tr>';
*/
if($fulldir != $userroot)
{
$upperdir = "";
#haal de juiste upper dir locatie op
$split = explode('/', $dir);
if( $split[count($split)-1] == '' )
{
#haal de lege dir uit de lijst
array_pop($split);
}
if( count($split)==1 )
{
$upperdir = '';
}
else
{
for( $i=0; $i < count($split)-1; $i++ )
{
$upperdir = $upperdir.$split[$i].'/';
}
}
}
/*
echo'<tr bgcolor="#999999">
<td style="text-align: right;"><img src="images/updir.gif" style="width: 16px; height: 14px; border: none;" alt=""
align="absmiddle" /></td>
<td height=20 onclick="java script:open_dir(\''.$upperdir.'\');" style="cursor: pointer;"><b> <u>Parent Directory</u></b></td>
<td></td>
<td> </td>
<td style="width: 70px;"></td>
<td style="text-align: right; width: 70px;"></td>
</tr>';
}
*/
#get contents of dir
$res = ContentsOfDir($fulldir);
//print_r($res['dirs']);
#list dirs
if( is_array($res['dirs']) )
{
for( $i=0; $i < count($res['dirs']); $i++)
{
$dirname = $res['dirs'][$i];
echo '<tr bgcolor="#CCCCCC">
<td style="text-align: right;"><img src="images/icon_dir.gif" style="width: 16px; height: 14px; border: none;" alt="" align="absmiddle" /></td>
<td onclick="java script:open_dir(\''.$dir.$dirname.'/\');" style="cursor: pointer;" onmouseover="this.style.backgroundColor=\'#2B6CFF\'; this.style.color=\'white\';" onmouseout="this.style.backgroundColor=\'\';
this.style.color=\'\';"><b> '.$dirname.'</b></td>
<td></td>
<td style="text-align: right; width: 120px;">Directory ('.ItemsInDir($fulldir.'/'.$dirname).' items) </td>
<td style="width: 70px;"></td>
<td style="text-align: right; width: 70px;">';
}
}
#list files
if( is_array($res['files']) )
{
for( $i=0; $i < count($res['files']); $i++)
{
$filename = $res['files'][$i];
$filepath = $fulldir.'/'.$filename;
$desc = FileDescriptionGen($filepath);
echo '<tr bgcolor="#CCCCCC">
<td style="text-align: right;"><img src="images/'.$desc['picfilename'].'" style="width: 16px; height: 14px; border: none;" alt="" align="absmiddle" /></td>
<td width="45%" style="cursor: pointer;" onmouseover="this.style.backgroundColor=\'#2B6CFF\'; this.style.color=
\'white\';" onmouseout="this.style.backgroundColor=\'\'; this.style.color=\'\';"> '.$filename.' </td>';
$set=ItemsInDir($filename);
return $set['files'];
}
}
?>