Page 1 of 1

Image Gallery - how to sort images. [SOLVED]

Posted: Mon Oct 08, 2012 7:31 am
by rabatos
Following the Automatic Image Gallery System.

Is there a way to display the images in a certain order.

Basically I want to have the images displayed in the order of the most recently added image.

So date order.

I have a file upload function, which I can use to add new photos to the gallery,

hence why I'd like to display new images first.

If anyone can help, thanks

Re: Image Gallery - how to sort images. [SOLVED]

Posted: Mon Oct 08, 2012 7:56 am
by rabatos
I've found the solution.
$images = glob("*.{jpg,jpeg,png,gif}", GLOB_BRACE);
 
array_multisort(
	array_map( 'filemtime', $images ),
	SORT_NUMERIC,
	SORT_DESC,
	$images
);
The array_multisort() function is explained here:
http://www.w3schools.com/php/func_array_multisort.asp

Re: Image Gallery - how to sort images. [SOLVED]

Posted: Wed Oct 10, 2012 7:46 pm
by jacek
I just learnt something :P

I was going to suggest a usort() but that way looks much nicer,

Re: Image Gallery - how to sort images. [SOLVED]

Posted: Fri Oct 12, 2012 10:25 am
by rabatos
haha, you're welcome.