<?php
// 2011-06 johnpfeiffer sort by filename or filename last modified timestamp
print "<pre>\n";
print ' foreach ( $filelist as $key => $row ) ' . "<br />\n";
print ' { $namecolumn[ $key ] = $row[ "name" ]; ' . "<br />\n";
print ' $lastmodifiedtimestampcolumn[ $key ] = $row[ "lastmodifiedtimestamp" ]; }' . " <br />\n";
print ' array_multisort( $lastmodifiedtimestampcolumn, SORT_DESC, $namecolumn, SORT_DESC, $filelist);' ."<br />\n";
print ' displayListing( $filelist );' . " <br />\n";
print ' </pre>';
function displayInfoAsTableRow( $filename , $filelastmodifiedtimestamp )
{
if( !is_null( $filename ) && !is_null( $filelastmodifiedtimestamp ) )
{
print "<tr>";
print "<td>" . $filename . "</td>";
print "<td>" . $filelastmodifiedtimestamp . "</td>";
print "<td>" . date( "Y-m-d H:s T", $filelastmodifiedtimestamp ) . "</td>";
print "</tr>\n";
}
} //end displayFileInformation()
function displayListing( $filelist )
{
print "<table>\n";
foreach( $filelist as $key => $value )
{
displayInfoAsTableRow( $filelist[ $key ]['name'] , $filelist[ $key ]['lastmodifiedtimestamp'] );
}
print "</table>";
} // end displayListing()
date_default_timezone_set('UTC');
clearstatcache();
$currentdirectory = getcwd();
$currentydirectoryhandle = opendir( $currentdirectory );
if( $currentydirectoryhandle )
{
$name = readdir( $currentydirectoryhandle );
while( $name !== false )
{
if( $name != "." && $name != ".." && is_file($name) )
{
$lastmodifiedtimestamp = filemtime( $name );
$filelist[] = array( "name" => $name, "lastmodifiedtimestamp" => $lastmodifiedtimestamp );
}
else
{
$lastmodifiedtimestamp = filemtime( $name );
$dirlist[] = array( "name" => $name, "lastmodifiedtimestamp" => $lastmodifiedtimestamp );
}
$name = readdir( $currentydirectoryhandle );
}
closedir( $currentydirectoryhandle );
} //end if
foreach ( $dirlist as $key => $row )
{
$namecolumn[ $key ] = $row[ "name" ];
$lastmodifiedtimestampcolumn[ $key ] = $row[ "lastmodifiedtimestamp" ];
}
array_multisort( $lastmodifiedtimestampcolumn, SORT_DESC, $namecolumn, SORT_DESC, $dirlist);
displayListing( $dirlist );
print "<br\> <br\> <br\> \n";
foreach ( $filelist as $key => $row )
{
$namecolumn[ $key ] = $row[ "name" ];
$lastmodifiedtimestampcolumn[ $key ] = $row[ "lastmodifiedtimestamp" ];
}
array_multisort( $lastmodifiedtimestampcolumn, SORT_DESC, $namecolumn, SORT_DESC, $filelist);
displayListing( $filelist );
// echo $_GET["sortedby"]; <br />
include( $_SERVER["DOCUMENT_ROOT"] . "/includes/foot.txt");
?>