RE: [PHP] Need to find newest file in dirs
| From: | Dave at Sinewaves.net | Date: | Thu, 08 Aug 2002 16:57:46 +0000 |
| Subject: | RE: [PHP] Need to find newest file in dirs | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111714@lists.php.net to get a copy of this message | ||
What has always worked for me is creating a simple log include file that
gets updated every time someone uploads an image. Contents will looks
something like this:
last_added.inc :
<?
$username = 'whatever';
$time_last_added = 'June 21, 2002 6:39pm';
$path_to_file = '/path/to/your/uploaded_pic.jpg';
// you can declare any other particulars you would like:
// - email address of user (to be linked to username)
// - size of file
// etc...
?>
Then whenever someone uploads an image, just set the $time_last_added to the
current date ( date() ) and overwrite the log file completely.
That way, anywhere on your site you'd like to put the "last file added"
information, all you have to do is include this log file.
This could be used within each user directory as well, and it will save you
some directory-reading overhead (at the expense of slightly more server
space).
Try it out - I think you'll agree it's a nice, configurable way to do it.
Hope this helps.
Dave
-----Original Message-----
From: Mike Carter [mailto:mikec@aviate.org]
Sent: Thursday, August 08, 2002 7:55 AM
To: php-general@lists.php.net
Subject: [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