RE: [PHP] File ordering
| From: | Ford, Mike [LSS] | Date: | Tue, 12 Aug 2003 13:34:58 +0000 |
| Subject: | RE: [PHP] File ordering | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-159276@lists.php.net to get a copy of this message | ||
On 12 August 2003 12:50, Katherine Barry wrote:
> I am doing a 'readdir' on a subdirectory. I did my file naming
> counting on it ordering based on numbering... But when I do the
> readdir it isn't doing it. My naming convention 002_2003_66.jpg would
> indicate the 66th picture for the month of Feb in 2003. This gave me
> automatic sorting. So I thought. But it doesn't seem to be doing it.
> The server is a linux server ((IStop/Doncaster consulting) and I
> don't see why the ordering is screwing up.
You can't predict what order the files will be presented in when you do a
readdir -- you'll probably find they're in the same order you get when you
do a raw 'ls' command with no sorting options, which depends on how the OS
allocates space to store directory information (which almost certainly isn't
in the order files are created!). To get them in the order you want, just
sort them in PHP.
The filename format you've chosen is also not good for sorting -- it may be
ok for this year, but when you start creating files in 2004, you'll probably
get an order like:
001_2003_01
001_2003_02
001_2004_01
001_2004_02
002_2003_01
002_2003_02
002_2004_01
002_2004_02
etc.
(i.e. all files for January, subsorted by year, subsubsorted by image
number; then files for February, by year, by image no.; then March, etc.).
I would recommend a format more like yyyy_mm_nn (e.g. 2003_08_66 for 66th
image in August 2003).
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211