Re: Need to find newest file in dirs
| From: | Mike Carter | Date: | Thu, 08 Aug 2002 18:09:14 +0000 |
| Subject: | Re: Need to find newest file in dirs | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111697@lists.php.net to get a copy of this message | ||
Thanks for all the ideas, folks. I appreciate the help.
Here's the final solution, for those interested. :)
function latest( $path ) {
// return the date of the latest file in the given directory.
global $oldfile; // the oldest file found.
global $modtime; // the latest mod time for the file
$modtime = 0;
clearstatcache; // clear the cache.
// open user dir and grab files
$theDir = opendir( $path );
while( $file = readdir( $theDir )) {
if( eregi( ".jpg|.gif|.bmp", $file )) {
$mtime = filemtime( $path . "/" . $file );
if( $mtime > $modtime ) {
$oldFile = $file;
$modtime = $mtime;
}
}
}
closedir( $theDir );
if( empty( $modtime ))
$modtime = "<FONT COLOR=\"#99FF33\"><I>No
pics</I></FONT>";
else
$modtime = "<FONT COLOR=\"#99FF33\"><I>" . date(
'm/d/Y',
$modtime) . "</I></FONT>";
return $modtime;
}
"Michael Carter" <mcarter@ragingwire.com> wrote in message
news:DADAF19595FEB54494DA4353AF77D1B7764F5E@SMF-EXCHANGE.sac.ragingwire.net.
..
Thanks, Justin.
Yes, I agree on the OS issues. For the record, I'm using Solaris 2.6.
The uploads are via FTP, so I *could* look at the logfiles for the last
upload sorted by authorized users, but I was hoping for a php specific
solution. I considered writing an upload page in php, but given ftp's
integration into Microsloth Exploder, it'd be a lot of work that is
already addressed.
What I was looking for was something akin to a recurse of the user's
directories, grabbing the image files, comaring dates and selecting the
latest for that user. Then I was hoping to end up with an array of user
=> latest file/date. From that I would select the "newest" entry and
display that user's name.
Come to think about it, it would be even better to perhaps show the
*last* date *per user* that a file was uploaded as well. Of course, if I
can get over the initial hump this would be icing. :)
#mikec
-----Original Message-----
From: Justin French [mailto:justin@indent.com.au]
Sent: Thursday, August 08, 2002 8:07 AM
To: Mike Carter; php-general@lists.php.net
Subject: Re: [PHP] Need to find newest file in dirs
This will be very OS-specific. The other problem will be that I *think*
the
only date associated with a file is the date last modified, NOT the date
last written to HDD, but of course, that will vary with some OS's.
When they upload, do they FTP, or do it via PHP scripts / browser?
If so, then you can keep track of the latest files with either the file
system or with a mysql database...
Justin French
on 09/08/02 12:55 AM, Mike Carter (mikec@aviate.org) wrote:
> 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
>
>