note 89517 added to function.opendir
| From: | RichardBronosky at osu1 dot php dot net | Date: | Thu, 12 Mar 2009 05:14:23 +0000 |
| Subject: | note 89517 added to function.opendir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151756@lists.php.net to get a copy of this message | ||
The easiest way to get a dir listing and sort it is to exec() out to ls (eg:'ls -t'). But,
that is considered "unsafe". My hosting company finally caught me doing it so here is my
fastest solution. (Lucky for me each file is created with a Unix Timestamp at the end of the name
and no other numbers in it.)
<?php
#exec('ls -t ./images/motion_detection/', $files); # They outlawed exec, so now I have to
do it by hand.
if ($handle = opendir('./images/motion_detection/')) {
$files=array();
while (false !== ($file = readdir($handle))) {
$files[$file] = preg_replace('/[^0-9]/', '', $file); # Timestamps may
not be unique, file names are.
}
closedir($handle);
arsort($files);
$files=array_keys($files);
}
?>
Before you go copying someone's bloat kitchen sink function/class, consider what you have and
what you really need.
----
Server IP: 64.71.164.2
Probable Submitter: 76.20.201.249
----
Manual Page -- http://www.php.net/manual/en/function.opendir.php
Edit -- https://master.php.net/note/edit/89517
Del: integrated -- https://master.php.net/note/delete/89517/integrated
Del: useless -- https://master.php.net/note/delete/89517/useless
Del: bad code -- https://master.php.net/note/delete/89517/bad+code
Del: spam -- https://master.php.net/note/delete/89517/spam
Del: non-english -- https://master.php.net/note/delete/89517/non-english
Del: in docs -- https://master.php.net/note/delete/89517/in+docs
Del: other reasons-- https://master.php.net/note/delete/89517
Reject -- https://master.php.net/note/reject/89517
Search -- https://master.php.net/manage/user-notes.php