03-05-2004, 03:39 PM | #1 (permalink) |
Loves my girl in thongs
Location: North of Mexico, South of Canada
|
[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?
__________________
Seen on an employer evaluation: "The wheel is turning but the hamsters dead" ____________________________ Is arch13 really a porn diety ? find out after the film at 11. -Nanofever |
03-05-2004, 07:18 PM | #2 (permalink) |
Fluxing wildly...
Location: Auckland, New Zealand
|
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:
__________________
flux (n.) Medicine. The discharge of large quantities of fluid material from the body, especially the discharge of watery feces from the intestines. Last edited by MrFlux; 03-05-2004 at 07:25 PM.. |
03-05-2004, 08:06 PM | #3 (permalink) |
Fluxing wildly...
Location: Auckland, New Zealand
|
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...
__________________
flux (n.) Medicine. The discharge of large quantities of fluid material from the body, especially the discharge of watery feces from the intestines. Last edited by MrFlux; 03-05-2004 at 08:11 PM.. |
03-07-2004, 01:52 PM | #4 (permalink) |
Tilted
Location: Tha Boro
|
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:
__________________
I try to take life one day at a time, but sometimes several days attack me at once. |
Tags |
date, images, ordering, php |
|
|