php $_FILES error code returning an unexpected error
<p>I have some code that allows users to upload multiple files at once. It was never getting to a specific point after the upload, so I put in an echo to test for the value of the error code, and it's returning a value that I'm not sure I understand. Here's the code:</p>

<pre><code>    $tmpTarget = PCBUG_UPLOADPATH;
    foreach ($_FILES["attachments"]["error"] as $key =&gt; $error) {
       if ($error == UPLOAD_ERR_OK) {
            $tmp_name = $_FILES["attachments"]["tmp_name"][$key];
            $name = str_replace(" ", "_", $_FILES["attachments"]["name"][$key]);
            move_uploaded_file($tmp_name, "$tmpTarget/$name");
            @unlink($_FILES["attachments"]["tmp_name"][$key]);
        }
        else {
            $errorFlag = true;
            echo "error = $error";
            exit;
        }
    }
</code></pre>

<p>The code that creates the attachments field looks like this:</p>

<pre><code>for($i=1; $i&lt;=$max_no_img; $i++){
    echo "&lt;input type=file name='attachments[]' class='bginput'&gt;&lt;br /&gt;";
}
</code></pre>

<p>where <code>$max_no_img</code> is a variable set further up in the code, and <code>PCBUG_UPLOAD</code> path is a constant defined in an included file.</p>

<p>Here's what's confusing: after I submit my form, I go and look in my uploads directory, and the files I've selected through the form are there - they uploaded correctly. However, the code is jumping into the else clause and $error is returning 4, which <a href="http://php.net/manual/en/features.file-upload.errors.php" rel="nofollow">the php manual</a> indicates means that no file was uploaded.</p>

<p>Any ideas? The files very clearly are getting where they're supposed to. Is there some other definition of "uploaded" that isn't happening?</p>
