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.


Edited by Veltu
Link to comment
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.

Edited by requinix
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

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.