![]() |
[PHP] ordering images by date
I have a basic php thumbnail program that grabs my thumbs out of a ../images/thumb folder inside my image folder. the code uses thumbs named the same as the full scale images in the parent directory.
The php takes care of building a table and arranging the thumbs into the table for which i can define the amount of colums and rows. Recently I've taken an interest and developed a need to have these thumbs placed in date order instead of alphabetical order as they currently are. I assume the *nix files system is just sticking them in alpha order as there is no php code currently dictating the order of the thumbs. It justs uses the order in which it reads them from the directory. Now is there any code or resources that i could use (actual code is prefferable as it would then work on any computer) that would tell the basic thumbnail program to place the images in the user defined table in date order? |
I can't quite work out the logic in my head but im pretty sure you could do it using getlastmod() and sort($array,SORT_NUMERIC)
Personally, I use a database for my photo gallery, with a date column so I can sort by date added... You could use a multidimensional array, each file has a stored filename and date modified e.g. $thumbs[0][0] = 'filename.jpg' $thumbs[0][1] = '324729874' then use array_multisort() to sort by [i][1] then just display the images using foreach second edit: here's some code posted on PHP.net for sorting multidimensional arrays: PHP Code:
|
Huzzah! Here is how you can sort your array if you have the date/filename in it... much simpler than i thought:
PHP Code:
Edit: oh, here's the output of that script: Name: filename3.jpg Num: 123 Name: filename.jpg Num: 231 Name: filename2.jpg Num: 312 To reverse this (i.e. output by LATEST date instead of earliest) just stick in $thumbs = reverse_array($thumbs) before your output code... |
This snippet sorts an array of file references by the last changed date of the file by retriving an array of dates and then using array_multisort to sort the array of filenames by the array of dates
PHP Code:
|
What kind of language doesn't have hashes, for God's sake? *shudder*
(Edit: I'm kidding, PHP zealots! I'm about to join your ranks, ok? Put down the pitchforks!) |
All times are GMT -8. The time now is 10:08 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project