Good day !!
I am using this code below, to display my directory and it is working great, the only thing is that I would like to sort it by date starting with the most recent, can you help ??
Thanks
+++++++++++++
<?php
/*
This little script is by Gary C, knightcommander@knightcommander.karoo.co.uk.
Please leave this note here if you use it.
HOWTO
installing
just copy this script and the images folder to the directory you want to list, you can rename this script to suit your needs.
it shouldn't be to hard to integrate this script into another page
Using desc files:
this is a very easy function to use. This feature allows you to add descriptions of the file to the file list;
these may include instructions or other bits of information. The desc files can include html tags and PHP (Not recommended).
1) Create a new text file with your favorite text editor.
2) Add the text you want.
3) Save the file with the same full file name as the file your describing then add ".desc" to the end.
Here's an example: the name of the file is "test.mp3" so the desc file should be named "test.mp3.desc" simple eh?
Updates
- 19 August 2003
-> First Ever public release yay ;-)
-> added file description functions (see howto above).
-> Still only works two dirs deep 🙁
-> Added Delphi file types and icon 😉
-> and that's it for now, have fun.
*/
?>
<html>
<!-- Creation date: 08/05/2003 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="Gary Crowhurst">
<meta name="generator" content="AceHTML 5 Pro">
</head>
<body>
<center><H3>Directory Listing</H3></center>
<?PHP
Function GetDesc($filename){
if(File_Exists("$filename" . ".desc")){
$contents = file("$filename" . ".desc");
$length = sizeof($contents);
for($counter=0; $counter<$length; $counter++)
{
Return " - $contents[$counter]<br>";
}
}
}
echo "<table width='90%' border='1' bordercolor='000000' align='center' bgcolor='#EAEAEA'>\n";
echo "<tr>\n";
echo "<td width=1%></td>\n";
echo "<td width='85%'><b>File Name</b></td>\n";
echo "<td><b>File Size</b></td>\n";
echo "</tr>\n";
if ($Folder=="") {
$Folder="./";
}ELSE{
$Folder = "$Folder/";
}
function get_true_size($FileSize) {
IF ($FileSize / 1024 > 1024) {
Return "" . Round($FileSize / 1024 / 1024 , 2) . " GB";
}ELSE{
if ($FileSize > 1024){
Return "" . Round($FileSize / 1024 , 2) . " MB";
}ELSE{
if ($FileSize < 1024) {
Return "" . Round($FileSize , 2) . " KB";
}
}
}
}
function get_file_type($filename) {
ereg( ".*.([a-zA-z0-9]{0,5})$", $filename, $regs );
$f_ext = $regs[1];
$types['image'] = array ('jpg', 'gif','png','jpeg','bmp');
$types['adob'] = array ('pdf');
$types['lotus'] = array ('123');
$types['text'] = array ('text','txt','nfo','dis','diz');
$types['music'] = array ('mp3','ogg','wav','mid','midi','rmi','mod','it','s3m');
$types['scripts'] = array ('php','phps','htm','html','js');
$types['zip'] = array ('zip','rar','ace');
$types['exec'] = array ('exe','bat');
$types['delphi'] = array ('dpr','pas','dfm','rc','cfg');
$types['desc'] = array ('desc');
foreach ($types as $k => $v) {
if (in_array($f_ext, $v)) {
return $k;
break;
}
}
return "unknown";
}
if ($handle = opendir($Folder)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($Folder . $file)) {
echo "<TR>";
echo "<td><img src='./images/folder.gif'></td>\n";
echo "<td onmouseover='this.style.background=\"DEDEDE\";' onmouseout='this.style.background=\"#EAEAEA\";'><a href='index2.php?Folder=$file/'>$file</a>";
echo GetDesc($file);
echo "</td>\n";
echo "<td>";
echo "</td>\n";
echo "</tr>\n";
}
}
}
closedir($handle);
}
if ($handle = opendir($Folder)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($Folder . $file)) {
}ELSE{
if (get_file_type($file) == "scripts") {
echo "<TR>";
echo "<td><img src='../images/script.gif'></td>\n";
echo "<td onmouseover='this.style.background=\"DEDEDE\";' onmouseout='this.style.background=\"#EAEAEA\";'><a href='$Folder" . "$file'>$file</a>\n";
echo GetDesc($file);
echo "</td>\n";
echo "<td>";
echo Get_True_size(FileSize($Folder . $file) / 1024 );
$TotalFileSize += FileSize($Folder . $file) / 1024;
echo "</td>\n";
echo "</tr>\n";
}
ELSE{
if (get_file_type($file) == "adob") {
echo "<TR>";
echo "<td><img src='./images/adob.gif'></td>\n";
echo "<td onmouseover='this.style.background=\"DEDEDE\";' onmouseout='this.style.background=\"#EAEAEA\";'><a href='$Folder" . "$file'>$file</a>\n";
echo GetDesc($file);
echo "</td>\n";
echo "<td>";
echo Get_True_size(FileSize($Folder . $file) / 1024 );
$TotalFileSize += FileSize($Folder . $file) / 1024;
echo "</td>\n";
echo "</tr>\n";
}
ELSE{
if (get_file_type($file) == "lotus") {
echo "<TR>";
echo "<td><img src='../images/lotus.gif'></td>\n";
echo "<td onmouseover='this.style.background=\"DEDEDE\";' onmouseout='this.style.background=\"#EAEAEA\";'><a href='$Folder" . "$file'>$file</a>\n";
echo GetDesc($file);
echo "</td>\n";
echo "<td>";
echo Get_True_size(FileSize($Folder . $file) / 1024 );
$TotalFileSize += FileSize($Folder . $file) / 1024;
echo "</td>\n";
echo "</tr>\n";
}
ELSE{
if (get_file_type($file) == "text") {
echo "<TR>";
echo "<td><img src='../images/text.gif'></td>\n";
echo "<td onmouseover='this.style.background=\"DEDEDE\";' onmouseout='this.style.background=\"#EAEAEA\";'><a href='$Folder" . "$file'>$file</a>\n";
echo GetDesc($file);
echo "</td>\n";
echo "<td>";
echo Get_True_size(FileSize($Folder . $file) / 1024 );
$TotalFileSize += FileSize($Folder . $file) / 1024;
echo "</td>\n";
echo "</tr>\n";
}ELSE{
if (get_file_type($file) == "music") {
echo "<TR>";
echo "<td><img src='../images/sound.gif'></td>\n";
echo "<td onmouseover='this.style.background=\"DEDEDE\";' onmouseout='this.style.background=\"#EAEAEA\";'><a href='$Folder" . "$file'>$file</a>\n";
echo GetDesc($file);
echo "</td>\n";
echo "<td>";
echo Get_True_size(FileSize($Folder . $file) / 1024 );
$TotalFileSize += FileSize($Folder . $file) / 1024;
echo "</td>\n";
echo "</tr>\n";
}ELSE{
if (get_file_type($file) == "image") {
echo "<TR>";
echo "<td><img src='../images/image.gif'></td>\n";
echo "<td onmouseover='this.style.background=\"DEDEDE\";' onmouseout='this.style.background=\"#EAEAEA\";'><a href='$Folder" . "$file'>$file</a>\n";
echo GetDesc($file);
echo "</td>\n";
echo "<td>";
echo Get_True_size(FileSize($Folder . $file) / 1024 );
$TotalFileSize += FileSize($Folder . $file) / 1024;
echo "</td>\n";
echo "</tr>\n";
}ELSE{
if (get_file_type($file) == "zip") {
echo "<TR>";
echo "<td><img src='../images/zip.gif'></td>\n";
echo "<td onmouseover='this.style.background=\"DEDEDE\";' onmouseout='this.style.background=\"#EAEAEA\";'><a href='$Folder" . "$file'>$file</a>\n";
echo GetDesc($file);
echo "</td>\n";
echo "<td>";
echo Get_True_size(FileSize($Folder . $file) / 1024 );
$TotalFileSize += FileSize($Folder . $file) / 1024;
echo "</td>\n";
echo "</tr>\n";
}ELSE{
if (get_file_type($file) == "exec") {
echo "<TR>";
echo "<td><img src='../images/binary.gif'></td>\n";
echo "<td onmouseover='this.style.background=\"DEDEDE\";' onmouseout='this.style.background=\"#EAEAEA\";'><a href='$Folder" . "$file'>$file</a>\n";
echo GetDesc($file);
echo "</td>\n";
echo "<td>";
echo Get_True_size(FileSize($Folder . $file) / 1024 );
$TotalFileSize += FileSize($Folder . $file) / 1024;
echo "</td>\n";
echo "</tr>\n";
}ELSE{
if (get_file_type($file) == "unknown") {
echo "<TR>";
echo "<td><img src='../images/unknown.gif'></td>\n";
echo "<td onmouseover='this.style.background=\"DEDEDE\";' onmouseout='this.style.background=\"#EAEAEA\";'><a href='$Folder" . "$file'>$file</a>\n";
echo GetDesc($file);
echo "</td>\n";
echo "<td>\n";
echo Get_True_size(FileSize($Folder . $file) / 1024 );
$TotalFileSize += FileSize($Folder . $file) / 1024;
echo "</td>\n";
echo "</tr>\n";
}ELSE{
if (get_file_type($file) == "delphi") {
echo "<TR>";
echo "<td><img src='../images/delphi.gif'></td>\n";
echo "<td onmouseover='this.style.background=\"DEDEDE\";' onmouseout='this.style.background=\"#EAEAEA\";'><a href='$Folder" . "$file'>$file</a>\n";
echo GetDesc($file);
echo "</td>\n";
echo "<td>\n";
echo Get_True_size(FileSize($Folder . $file) / 1024 );
$TotalFileSize += FileSize($Folder . $file) / 1024;
echo "</td>\n";
echo "</tr>\n";
}
}
}
}
}
}
}
}}
}
}
}}
closedir($handle);
}
echo "<tr>\n";
echo "<td></td>\n";
echo "<td><b>Total Space taken by files is: " . Get_True_size($TotalFileSize) . "</b></td>\n";
echo "<td></td>\n";
echo "</tr>\n";
echo "</table>\n";
?>
</body>
</html>