Jump to content

PHP file upload sorting order


Veltu

Recommended Posts

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.


Link to comment
https://forums.phpfreaks.com/topic/293055-php-file-upload-sorting-order/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.