Reply to Re: readdir() doesn't maintain order

Your name:

Reply:


Posted by Andy Hassall on 09/15/07 16:03

On Sat, 15 Sep 2007 08:10:46 -0700, Semi Confused <PostInGroups@wherever.com>
wrote:

>$dir = opendir("thumbs");
>//read files in the dir
>while (($file = readdir($dir)) !== false)
>
>Was reviewing a few of the pages I made and something seemed odd.
>Further investigation showed that my thumbs are not in the order of the
>filesystem.
>
>So it starts at pic 1370 and ends back at 1359. In reality the pics
>start at 1359 and end at 1424. Maybe the question is how is the file
>system really sorted?

Yes.

>I haven't tried to implement the other methods shown this week and
>maybe one doesn't do this?
>or
>Readdir into an array?

Yes, or scandir() (which gives a sorted array), or glob() (which both filters
and sorts), but in either case you may still want a different sort order - in
particular look at natsort().

http://php.net/scandir
http://php.net/glob
http://php.net/natsort

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация