Veltu Posted December 12, 2014 Share Posted December 12, 2014 (edited) I'm looking to order my upload files in a specific order. I believe the default is a random upload order, but I would like to change this based on the file name, which I'm having difficulty with. The file names would be for example; '01 smiley' '02 dog' '03 cat' Currently I used a 'Drag & Drop' multiple file upload although this just uploads in any random order to my database table, I'd like to upload it by numeric order as above. Code so far (upload code works, just the order needs work)... $count = count($_FILES['upload']['name']); $in=0; while($in<$count) { //upload here $in++; } I think I need to sort()? before my while loop, but having difficulty getting this correct. How would I be able to sort each file into a correct order. Many thanks. Edited December 12, 2014 by Veltu Quote Link to comment https://forums.phpfreaks.com/topic/293055-php-file-upload-sorting-order/ Share on other sites More sharing options...
requinix Posted December 12, 2014 Share Posted December 12, 2014 (edited) PHP will add files in the order they're presented, so it's up to the drag and drop code to deal with that. You can still sort in PHP, of course. There are four arrays in $_FILES that you have to sort at once so rather than sort() use array_multisort: you give it the four arrays (name, tmp_name, error, type) and it'll sort one and rearrange the rest accordingly. Check the examples there and give it a shot. Edited December 12, 2014 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/293055-php-file-upload-sorting-order/#findComment-1499456 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.