mikem562 Posted August 13, 2009 Share Posted August 13, 2009 I have the following script which generated xml for me, I need a way though so the first <image> node is the newest image, and the last node is the oldest. so instead of it doing it via filename I would like to-do it by the date it was last touched. I plan on uploading images and upon running this script I want the most recently uploaded ones at the top... <?php $dir = '../galleries/music/'; $file_ext = "img.jpg"; $play_list = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"; $play_list .= "<content>\n"; $play_list .= "<gallery>\n"; // Open directory, read contents and add to file_list if correct file_type if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..') { $name_array = explode('_', $file); if ($name_array[1] == $file_ext) { $file_img = "$file"; $file_tmb = str_replace("_img", "_tmb", "$file"); $play_list .= "<image Thumb=\"$file_tmb\" Large=\"$file_img\"></image>\n"; } } } closedir($dh); $play_list .= "</gallery>\n"; $play_list .= "</content>\n"; $wdir = ''.$dir.'images1.xml'; $f=fopen("$wdir","w") or die("Could not open and empty the file"); fwrite($f,$play_list) or die("Could not write to the file"); fclose($f) or die ("Could not close the resource"); } } ?> Quote Link to comment Share on other sites More sharing options...
mikem562 Posted August 13, 2009 Author Share Posted August 13, 2009 I know I have to use the filemtime function to get the time of all the files in the array, but I'm still unsure how to sort them before it gets to this line here: $play_list .= "<image Thumb=\"$file_tmb\" Large=\"$file_img\"></image>\n"; Quote Link to comment Share on other sites More sharing options...
mikem562 Posted August 13, 2009 Author Share Posted August 13, 2009 *bump* anyone? Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted August 13, 2009 Share Posted August 13, 2009 What kind of array structure you have? If the dates are the array keys and the dates are in standard ISO format (YYYY-MM-DD) you probably could use ksort() function. If not then you probably have to build your own function for the sorting. Quote Link to comment Share on other sites More sharing options...
mikem562 Posted August 13, 2009 Author Share Posted August 13, 2009 yea I'm not quite sure how to-do that... I'm like extra stuck on this one Quote Link to comment Share on other sites More sharing options...
mikem562 Posted August 13, 2009 Author Share Posted August 13, 2009 *bump* < i'll try one more bump. I've been playing with this all night and I just can't figure out how to get them to list by last modified :S Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.