Hi,
I have a problem with my little readdir script.
How do I sort the list by cathegories (size,type,date or name)
How do I know when it's a file or a dir for the "Type";
And how can I download a file?
If you click on ex.: c:\test.txt I want to be able to download it.
<?php
// listdir.php
ini_set("max_execution_time", "300");
$root = "c:";
include("./list.php");
if(empty($path)) { $batchpath = "$root"; } else { $batchpath = "$path"; }
echo"
<font face=\"Tahoma,Verdana,Arial,Helvetica\" size=\"2\" color=\"#000000\">
<table border=\"0\" cellspacing=\"1\" cellpadding=\"2\">
<tr bgcolor=\"#8a99e3\">
<td><font face=\"Tahoma,Verdana,Arial,Helvetica\" size=\"2\" color=\"#ffffff\"><b>Name</b></font></td>
<td width=\"60\" ><font face=\"Tahoma,Verdana,Arial,Helvetica\" size=\"2\" color=\"#ffffff\"><b>Size</b></font></td>
<td width=\"200\"><font face=\"Tahoma,Verdana,Arial,Helvetica\" size=\"2\" color=\"#ffffff\"><b>Type</b></font></td>
<td width=\"140\"><font face=\"Tahoma,Verdana,Arial,Helvetica\" size=\"2\" color=\"#ffffff\"><b>Date Modified</b></font></td>
</tr>\n\n";
$lf= new listfiles; $lf->showlist($batchpath);
echo" </table>
</font>";
?>
<?php
// list.php
$lastpath = str_replace("/$prepath","",$path);
if(!empty($prepath)) { echo"<p><b><a href=\"$PHP_SELF?path=$lastpath\">$lastpath</a> / $prepath</b></p>"; } else { echo"<b>$root</b>"; }
class listfiles{
var $version="1.0";
var $myfileextensions="()\$";
var $myrestrictedfiles="/|^\\.";
function showlist($batchpath){
$mydirectory=opendir($batchpath);
while($entryname=readdir($mydirectory)){
$a = eregi($this->myfileextensions,$entryname);
$b = !eregi($this->myrestrictedfiles,$entryname);
if ( $a && $b){
$myfiles["$entryname"]=$entryname;
}
}
if (is_array($myfiles)) {
asort($myfiles);
$i=0;
while (list($name,$value)=each($myfiles))
{
$i++;
if ($i%2) { $bgcolorm="bgcolor=\"#DADFF7\""; } else { $bgcolorm="bgcolor=\"#B7BFE5\""; }
$myfiledate = date("d/m/Y, H:i:s", filemtime("$batchpath/$name"));
$myfilesize = filesize("$batchpath/$name");
$myxfilesize = "$myfilesize";
if($myfilesize < 1125899906842624) { $myyfilesize = number_format($myfilesize/1099511627776,2,',','\''); $myxfilesize="$myyfilesize GB"; }
if($myfilesize < 1099511627776) { $myyfilesize = number_format($myfilesize/1073741824,2,',','\''); $myxfilesize="$myyfilesize GB"; }
if($myfilesize < 1073741824) { $myyfilesize = number_format($myfilesize/1048576,2,',','\''); $myxfilesize="$myyfilesize MB"; }
if($myfilesize < 1048576) { $myyfilesize = number_format($myfilesize/1024,2,',','\''); $myxfilesize="$myyfilesize KB"; }
if($myfilesize < 1024) { $myxfilesize = "$myfilesize B"; }
if($myfilesize == 0) { $myxfilesize = ""; }
$chopdot = explode(".", $name);
$renameext = str_replace(array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"),array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"),$chopdot[1]);
$myfileext = str_replace(array("acm","ani","avi","ax","bak","bat","bin","bkf","bmp","com","cfg","chm","cmd","cnt","cpl","css","cur","dat","dir","dll","doc","drv","exe","fla","gif","hlp","htm","html","ico","inc","inf","ini","iso","jpeg","jpg","log","mid","midi","mov","mp3","mp4","msg","msi","nrg","obd","oca","ocx","ocx","pdf","php","png","ppt","prx","psd","psp","rar","reg","scr","sql","swf","sys","tmp","ttf","txt","vbs","vxd","wav","wma","xls","xml","zip"),array("ACM File","Animated Cursor","Video Clip","AX File","Backup File","MS-DOS Batch File","BIN File","Microsoft Backup File","Windows Bitmap","MS-DOS Application","Microsoft Office Outlook Configuration File","Compiled HTML Help File","Windows NT Command Script","CNT File","Control Panel Extension","Cascading Style Sheet Document","Cursor","DAT File","Folder","Application Extension","Microsoft Word Document","Device Driver","Applications","Flash Document","GIF Image","Help File","HTML Document","HTML Document","Icon","Include File","Setup Information","Configuration Settings","ISO Image File","JPEG Image","JPEG Image","Log File","MIDI Sequence","MIDI Sequence","QuickTime Movie","MP3 Audio File","MP4 Audio File","Email Message","Windows Installer Package","Nero Project","Microsoft Binder","OCA File","ActiveX Control","OCX File","Adobe Acrobat Document","Hypertext Preprocessor","PNG Image","Microsoft PowerPoint Presentation","Windows Media Profile","Adobe Photoshop Image","Paint Shop Pro Image","WinRAR Archive","Registry File","Screen Saver","SQL File","Flash Movie","System File","Temp File","True Type Font","Text Document","VBScript Script File","Virtual Device Driver","Wave Sound","Microsoft Windows Media Audio","Microsoft Excel Worksheet","XML Document","Zip File Archive"),$renameext);
echo"
<tr $bgcolorm>
<td><font face=\"Tahoma,Verdana,Arial,Helvetica\" size=\"2\" color=\"#000000\"> <a href=\"$PHP_SELF?path=$batchpath/$name&prepath=$name\">$name</a> </font></td>
<td align=\"right\"><font face=\"Tahoma,Verdana,Arial,Helvetica\" size=\"2\" color=\"#000000\"> $myxfilesize </font></td>
<td><font face=\"Tahoma,Verdana,Arial,Helvetica\" size=\"2\" color=\"#000000\"> $myfileext </font></td>
<td align=\"right\"><font face=\"Tahoma,Verdana,Arial,Helvetica\" size=\"2\" color=\"#000000\"> $myfiledate </font></td>
</tr>\n";
}
}
else
{
echo"
<tr $bgcolorm>
<td colspan=\"4\"><font face=\"Tahoma,Verdana,Arial,Helvetica\" size=\"2\" color=\"#000000\"><p> <br>No File Found in<br>$batchpath</p></font></td>
</tr>\n";
}
closedir($mydirectory);
}
}
?>