Jochem Maas wrote:
Diogo Neves schreef:
On Wed, Sep 3, 2008 at 12:35 AM, Vernon <[EMAIL PROTECTED]> wrote:
I've gotten the one array down and I've figured out how to sort that
array,
however, I need to sort the array by the modified date of the file.
Here's
what I got so far:
<?php
// Open current directory
if($handle = opendir($dir)){
// Loop through all files
while(false !== ($file = readdir($handle))){
// Ignore hidden files
if(!preg_match("/^\./", $file)){
// Put dirs in $dirs[] and files in $files[]
if(is_dir($file)){
$dirs[] = $file;
}else{
$files[] = $file;
}
}
}
// Close directory
closedir($handle);
// if $files[] exists, sort it and print all elements in it.
if(is_array($files)){
//HERE IS MY CURRENT SORT WHICH I KNOW I NEED TO CHANGE BUT AM UNSURE
HOW
sort($files);
foreach($files as $file){
$completeFileName = $dir . $file;
//I WANT TO SORT BY THIS
echo date("m-d-Y", filemtime($completeFileName)) . "<br>";
}
}
}
?>
Any ideas on how to fix this? Thanks
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Hi,
<?php
$dir = '/tmp';
$files = scandir( $dir);
$files_new = array( );
foreach( $files as $file ) {
if( strrpos( $file, 'sess_' ) !== false ) {
$files_new[filemtime( $dir . '/' . $file )] = $file;
this totally breaks because file modification time is only accurate
to a second (many files can be modified in that time) ... appending
the file name to the key will fix that:
$files_new[filemtime( $dir . '/' . $file ).$file] = $file;
or flip the association around, because files are uniq and that file can
only have one modification time.
}
}
ksort( $files_new );
var_dump( $filesnew );
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php