Body: <p>I created a matrix with 1 type, 3 fields for user profile. I use front-end to upload file to documentUpload field. But I got PHP warning: <code>array_merge(): Argument #1 is not an array message</code>. I Google it and see <a href="https://github.com/am-impact/amforms/issues/29" rel="nofollow noreferrer">this issue</a>. I did try adding</p>
  
  <pre><code>if (empty($value)) {
      $value = array();
  }
  </code></pre>
  
  <p>But I still got the same issue. Not sure how I could resolve the issue. I see my file is uploaded to AWS S3. Looks it has issue to save it in Craft. Does anyone know how to solve it? Thanks</p>
  
  <p>Here is my code to upload file:</p>
  
  <pre><code>&lt;form method="post" accept-charset="UTF-8" enctype="multipart/form-data"&gt;
   {{ getCsrfInput() }}
  &lt;input type="hidden" name="action" value="users/saveUser"&gt;
  &lt;input type="hidden" name="fields[petRecords][new{{ next }}][type]" value="records"&gt;
  &lt;input type="hidden" name="fields[petRecords][new{{ next }}][enabled]" value="1"&gt;
  &lt;input type="file" name="fields[petRecords][new{{ next }}][fields][documentUpload]" /&gt;
  &lt;input type="text" name="fields[petRecords][new{{ next }}][fields][description]" /&gt;
  &lt;input type="text" name="fields[petRecords][new{{ next }}][fields][petIdNumber]" /&gt;
  &lt;input class="btn btn-primary btn-block btn-social" type="submit" value="continue"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><a href="https://i.sstatic.net/SACb5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/SACb5.png" alt="configuration"></a>
  My Craft CMS version is 2.6.2980
  <a href="https://i.sstatic.net/c7QwI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/c7QwI.png" alt="Error message"></a></p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-26T17:09:45.023Z
Comments.Text: Have you tried passing your file field as an array, adding `[]` at the end?`fields[petRecords][new{{ next }}][fields][documentUpload][]`
Comments.UserDisplayName: Matt Stein
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-26T17:24:54.373Z
Comments.Text: You're linking to an [amforms plugin](https://github.com/am-impact/amforms/issues/29) issue. Is this an amforms form?  Doesn't look like it because it's calling `users/saveUser`.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-26T18:28:05.733Z
Comments.Text: @matt-stein, Adding `[]` looks that issue is gone. but when I enter another file, I got error. After I refresh my page and add the file again, it allows me to add a file. Looks the tagetID is not loaded on the first time.
Comments.UserDisplayName: Angela Chan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-26T18:28:12.793Z
Comments.Text: `CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'targetId' cannot be null. The SQL statement executed was: INSERT INTO `craft_relations` (`fieldId`, `sourceId`, `sourceLocale`, `targetId`, `sortOrder`, `dateCreated`, `dateUpdated`, `uid`) VALUES (:row0_col0, :row0_col1, NULL, NULL, :row0_col4, :row0_col5, :row0_col6, :row0_col7). Bound with :row0_col0='98', :row0_col1='522', :row0_col4=1, :row0_col5='2017-05-26 18:22:39', :row0_col6='2017-05-26 18:22:39', :row0_col7='75187a4d-f2fc-4389-9c35-f42b9ba1f17c'`
Comments.UserDisplayName: Angela Chan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-26T18:28:57.087Z
Comments.Text: @BradBell, I'm not using amforms, looks I am on the wrong direction.
Comments.UserDisplayName: Angela Chan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-26T18:31:24.873Z
Comments.Text: If I'm following you, @AngelaChan, you would also need to add `multiple` to your field if you're attempting to add more than one file to it. Example [here in P&T's docs](https://craftcms.com/docs/assets-fields#uploading-files-from-front-end-entry-forms).
Comments.UserDisplayName: Matt Stein
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-26T23:41:14.207Z
Comments.Text: I see your new question [here](https://craftcms.stackexchange.com/questions/20603/cdbexception-error-when-upload-files-to-matrix-field-on-front-end), @AngelaChan. Can you add the `[]` fix as an answer to this one in case other people might have the same issue?
Comments.UserDisplayName: Brad Bell
Tags: <matrix><php><upload>
Title: Frontend upload asset to Matrix
ThreadText: # Frontend upload asset to Matrix
  
  (Asked by: username_0 on 2017-05-26)
  
  I created a matrix with 1 type, 3 fields for user profile. I use front-end to upload file to documentUpload field. But I got PHP warning: `array_merge(): Argument #1 is not an array message`. I Google it and see [this issue](https://github.com/am-impact/amforms/issues/29). I did try adding
  
  ```
  if (empty($value)) {
      $value = array();
  }
  
  ```
  
  But I still got the same issue. Not sure how I could resolve the issue. I see my file is uploaded to AWS S3. Looks it has issue to save it in Craft. Does anyone know how to solve it? Thanks
  
  Here is my code to upload file:
  
  ```
  <form method="post" accept-charset="UTF-8" enctype="multipart/form-data">
   {{ getCsrfInput() }}
  <input type="hidden" name="action" value="users/saveUser">
  <input type="hidden" name="fields[petRecords][new{{ next }}][type]" value="records">
  <input type="hidden" name="fields[petRecords][new{{ next }}][enabled]" value="1">
  <input type="file" name="fields[petRecords][new{{ next }}][fields][documentUpload]" />
  <input type="text" name="fields[petRecords][new{{ next }}][fields][description]" />
  <input type="text" name="fields[petRecords][new{{ next }}][fields][petIdNumber]" />
  <input class="btn btn-primary btn-block btn-social" type="submit" value="continue">
  </form>
  
  ```
  
  [![configuration](https://i.sstatic.net/SACb5.png)](https://i.sstatic.net/SACb5.png)
  My Craft CMS version is 2.6.2980
  [![Error message](https://i.sstatic.net/c7QwI.png)](https://i.sstatic.net/c7QwI.png)
  
  **Tags:** matrix, php, upload
  
  > **Comments:**
  > **username_1**: Have you tried passing your file field as an array, adding `[]` at the end?`fields[petRecords][new{{ next }}][fields][documentUpload][]`  
  > **username_2**: You're linking to an [amforms plugin](https://github.com/am-impact/amforms/issues/29) issue. Is this an amforms form?  Doesn't look like it because it's calling `users/saveUser`.  
  > **username_0**: @username_1, Adding `[]` looks that issue is gone. but when I enter another file, I got error. After I refresh my page and add the file again, it allows me to add a file. Looks the tagetID is not loaded on the first time.  
  > **username_0**: `CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'targetId' cannot be null. The SQL statement executed was: INSERT INTO `craft_relations` (`fieldId`, `sourceId`, `sourceLocale`, `targetId`, `sortOrder`, `dateCreated`, `dateUpdated`, `uid`) VALUES (:row0_col0, :row0_col1, NULL, NULL, :row0_col4, :row0_col5, :row0_col6, :row0_col7). Bound with :row0_col0='98', :row0_col1='522', :row0_col4=1, :row0_col5='2017-05-26 18:22:39', :row0_col6='2017-05-26 18:22:39', :row0_col7='75187a4d-f2fc-4389-9c35-f42b9ba1f17c'`  
  > **username_0**: @username_2, I'm not using amforms, looks I am on the wrong direction.  
  > **username_1**: If I'm following you, @username_0, you would also need to add `multiple` to your field if you're attempting to add more than one file to it. Example [here in P&T's docs](https://craftcms.com/docs/assets-fields#uploading-files-from-front-end-entry-forms).  
  > **username_2**: I see your new question [here](https://craftcms.stackexchange.com/questions/20603/cdbexception-error-when-upload-files-to-matrix-field-on-front-end), @username_0. Can you add the `[]` fix as an answer to this one in case other people might have the same issue?  
  
  ---
  
  ## 0 answers
  
  