PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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...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"; ... i've tried my darnedest for the past day and I just can't get it
You probably want to read all the records into an array of arrays (e.g. array(0 => array('filename'=>'foo.jpg', 'date'=>'2009-03-25')) ) and then use usort() to sort based on the dates.
I'm not quite sure how to-do that. I do flash not really PHP and the above script I have took me like 2days to piece together / read etc... would you be able to give me a simple example and then I can try to work it in:)
$files['filename'] = $file;
$files['timestamp'] = fileatime("$dir/$file"); // see the docs
The use the usort() method to sort. See the example in the documentation that I gave you the link to above. But in your case, you want to compare ($a['timestamp'] == $b['timestamp']) and ($a['timestamp'] < $b['timestamp']).
well it's 2:14am here, i've been working with both sets of these codes for the past 5hours or so, and I can yet to figure it out. I think I've got the array being built correctly with the
$files['filename'] = $file;
$files['timestamp'] = fileatime("$dir/$file"); // see the docs
code, yet I still can't get it to function correctly, if anyone has the time to throw it into my script correctly and post it that would be appreciated, until then I'll keep at it and let you know of my progress Thanks again everyone!