Jump to content

Get images and order them

Recommended Posts

I have a script that currently gets all the jpg files in a directory and then I sort them.

<?php$thumbslist = array();$counter = 0;$dir = "../images/websites";		$dh = opendir($dir);			while (($filename = readdir($dh)) !== false) {	if(strstr($filename, '.jpg')) { //images can only be jpg		$thumbslist[$counter] = $filename;		$counter++;	}}closedir($dh);			sort($thumbslist);			for($i = 0; $i <= count($thumbslist); $i++){	echo $thumbslist[$i].'<br />';}?>

Is there a way I could use to order them a certain way but that I could choose? It's always by groups of 2, 1 is small and the other is the large version.

Link to post
Share on other sites

hmmm k but what about if the values are image file names. Those images are websites I've created, I want to order them by order of creation. I'm not sure how the user-defined sorting would work.edit: I found a way to sort by keys instead. This should work pretty good. I'll give it a try.http://ca.php.net/ksort

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...