note 31666 deleted from function.readdir by tularis

From: Date: Sun, 13 May 2007 19:06:51 +0000
Subject: note 31666 deleted from function.readdir by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-126553@lists.php.net to get a copy of this message
Note Submitter: thebitman at attbi dot com ---- On sorting by date- no, you can't just use an associative array since some things /will/ be created on the same second. No reason why you can't append the filename to the time, though! (used md5() to kill any weird characters in a unique way) $dirpath = getcwd() . "/"; $dir = opendir($dirpath); $files = array(); while ($file = readdir($dir)) { $localpath = $dirpath.$file; if (is_file($localpath)) { $key = filemtime($localpath).md5($file); $files[$key] = $file; } } ksort($files); foreach ($files as $file) { echo "$file<br>"; }

« previous php.notes (#126553) next »