Difference in $_FILES structure when submitting and using XmlHttpRequest
<p>I'm building a file uploader using the javascript FileAPI and XmlHttpRequest with a fallback to uploading via a hidden iframe. Both uploads are processed with PHP.</p>

<p>I however found an annoying difference in the way the $_FILES array is structured. </p>

<p>When using the iframe fallback, the array will look like this: </p>

<pre><code>$_FILES = array(
    'files' =&gt; array(
        'name' =&gt; array(
            0 =&gt; 'name.jpg'
        ),
        'type' =&gt; array(
            0 =&gt; 'image/jpeg'
        )
        ...
    )
)
</code></pre>

<p>(I'm using multiple inputs called files[]) </p>

<p>When I upload using an XmlHttpRequest, the array looks like this:</p>

<pre><code>$_FILES = array(
    'filename' =&gt; array(
        'name' =&gt; 'name.jpg',
        'type' =&gt; 'image/jpeg'
        ...
    ),
    ...
)
</code></pre>

<p>Is there any way to make this behave the same way? Below you find how I build my xhr request:</p>

<pre><code>var data = new FormData(), xhr = new XMLHttpRequest();

data.append(file.name, file);

xhr.open('POST', 'process.php', true);

xhr.onload = function(e) {
    ...
};
xhr.send(data);
</code></pre>

<p>At the moment I parse the two different arrays like this, which seems to work.</p>

<pre><code> if(isset($_FILES['files']['name']))
 { // old skool $_FILES array
    foreach($_FILES['files'] as $key =&gt; $values)
    {
        foreach($values as $index =&gt; $value)
        {
            $files[$index][$key] = $value;
        }
    }
 } 
 else
 { // XMLHttpRequest $_FILES
    $files = $_FILES;
 }
</code></pre>
