Fix up lost keys when flattening $_FILES array and fix #1599

@andrewminton and I were playing with the upload field when I came across a situation where the file array did not have there keys (keys were numeric). I think the second commit fixes it.

The other commit is for #1599. Sorry I did the fix in the same branch as this one. You can cherry pick each one if you want.