0

I want to list all the images in a specific folder using FilesystemIterator. Over time that folder will be filled with a lot images, which will of course slow the system down.

I'm thinking about creating a pagination function, and only show for example 20 images at once. But I would like it to be sorted after the latest modified images (because this will make it easier for the user, not having to look through all the pages).

I don't want to put the entire directory in an array and then sort it, as that would kind of beat the purpose.

My question is, is it possible to set the sort order of FilesystemIterator?

dvlpr
  • 122
  • 1
  • 9
  • 1
    There's [no option for ordering](http://stackoverflow.com/questions/29102983/order-in-filesystemiterator). You'll have to materialize an iterator into an array for ordering it. (How large is that directory really?) – mario Jun 21 '15 at 19:58
  • It is an image upload directory, so in time, it could be holding thousands of images (like our current directory does and running our current script takes too long time, especially if the connection is slow). Is there perhaps a smarter way of handling it that I haven't thought of? – dvlpr Jun 21 '15 at 20:02

0 Answers0