dj-kenpo Posted June 2, 2007 Share Posted June 2, 2007 I'm for some reason not able to reverse the array of files I'm uplading. I have a form for uploading 4 images at once. becuase it's javascript on the form, it adds a newfile browse and places the previous one below. that means though when you hit upload, the first file you selected is the last, and vice veras. on the process end I'm suing this $photos_uploaded = $_FILES['photo_filename']; $photos_uploaded = array_reverse($photos_uploaded, true); true, makes no difference, and array_reverse makes no difference, I always get the last file first. for a sequential photo album, this is no good. can I not use array reverse on the array 'photo_filename' ? all 4 upload input slots are named 'photo_filename', so it should be a normal array of 'stuff' right? Quote Link to comment https://forums.phpfreaks.com/topic/53949-reverse-file-upload-order/ Share on other sites More sharing options...
marcus Posted June 2, 2007 Share Posted June 2, 2007 print_r($_FILES); What do you get? Is it even being passed? You can use the same variable name. I tested it with an array and it worked fine <?php $array = array('hello','goodbye','hi'); $x=1; foreach($array as $arra){ echo "$x. $arra<br>\n"; $x++; } echo "<br>\n"; $array = array_reverse($array,true); $y=1; foreach($array as $arra){ echo "$y. $arra<br>\n"; $y++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53949-reverse-file-upload-order/#findComment-266716 Share on other sites More sharing options...
dj-kenpo Posted June 2, 2007 Author Share Posted June 2, 2007 oh ya, the files are passed/uploaded/processed. everything works, but they go in reverse order.... are you sure $_FILES is treated exactly the same as a normal array? that's the only thing I can th9ink of as to why it wouldn't work. Quote Link to comment https://forums.phpfreaks.com/topic/53949-reverse-file-upload-order/#findComment-266720 Share on other sites More sharing options...
marcus Posted June 2, 2007 Share Posted June 2, 2007 Make the input slot: photo_filename[] $files = $_FILES['photo_filename']; $filenames = $_FILES['photo_filename']['name']; $filenames = array_reverse($filenames,true); $x=1; foreach($filenames as $file){ echo "$x. $file<br>\n"; $x++; } See if they go in reverse order here, but don't allow upload atm. Quote Link to comment https://forums.phpfreaks.com/topic/53949-reverse-file-upload-order/#findComment-266722 Share on other sites More sharing options...
dj-kenpo Posted June 2, 2007 Author Share Posted June 2, 2007 the input was already photo_filename[] so no change needed there, when I placed this above the files, it outputted in the correct order ie 1. IMG_0427.JPG 2. IMG_0428.JPG 3. IMG_0430.JPG 4. (with the normal script below in reverse order. the problem though is there's an extra blank one now for some reason. #4. it didn't seem to detect the size of the array correctly. I guess I could just add count($files) with a while loop to check, but that seems like a bandaid it would be better to have the array the correct size in the firs tplace. i'm tired after a long day so the answer is probably right there, I have no idea though, any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/53949-reverse-file-upload-order/#findComment-266726 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.