AW: [PHP] Need to find newest file in dirs
| From: | Bernhard Bauder | Date: | Thu, 08 Aug 2002 15:23:35 +0000 |
| Subject: | AW: [PHP] Need to find newest file in dirs | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111670@lists.php.net to get a copy of this message | ||
try this
$file_path = "randompics/"; //dir
$with_subdirs = true; // with subdirs?
$what_file = "/.+\.(gif$|jpg$|jpeg$)/i"; // what file? (reg ex)
$pics = addfiles($file_path,$what_file,$with_subdirs);
echo implode("<br>",$pics);
function addfiles($path,$what_file,$with_subdirs)
{
global $files;
$files[0] = "";
$handle = @opendir($path);
while ($file = @readdir ($handle)) {
if ($file != "." && $file != ".."){
if ($with_subdirs)
addfiles($path.$file."/",$what_file,$with_subdirs); // subdirs
if (preg_match($what_file , $file)) $files[] = $path.$file; //
addfile
}
}
@rewinddir ($handle);
@closedir($handle);
unset ($files[0]);
return $files;
}
Berni
www.php-resource.de
-----Ursprüngliche Nachricht-----
Von: Mike Carter [mailto:mikec@aviate.org]
Gesendet: Donnerstag, 8. August 2002 16:55
An: php-general@lists.php.net
Betreff: [PHP] Need to find newest file in dirs
Hello all. I have a number of directories into which users can deposit
pictures which are displayed on the Web through a PHP viewer I wrote.
I'd like to add the ability to show which user was the last to upload a file
to their directory so that as you visit the site you can see where new files
are without looking through every user's picture directory.
The directory structure is dynamic; user's dirs come and go, and their
contents change. Here is the current structure:
dir pics
|-- User1
|-- User2
|-- User3
The end result I am looking for is the directory name which contains the
newest *.gif or *.jpg file. Then I'll either colour-code the username on the
web site or just print a line saying "Last upload: August 10, 2002 by
User1". Any help would be appreciated!
Thanks..
MikeC
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php