Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7829773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:54:30+00:00 2026-06-02T10:54:30+00:00

I have a file input which is an array but what I had previously

  • 0

I have a file input which is an array but what I had previously no longer works, it seems to throw an error for multiple files, it just uploads the latest file. I can’t figure out what I have done wrong.

<input type="file" name="userfile[]" id="userfile" class="multi" />

Then in my controller:

$upload_files = $_FILES;
var_dump($upload_files['userfile']['name']);
// get the selected files out of the array
for($i = 0; $i < count($upload_files['userfile']['name']); $i++) {
   $_FILES['userfile'] = array(
      'name' => $upload_files['userfile']['name'][$i],
      'type' => $upload_files['userfile']['type'][$i],
      'tmp_name' => $upload_files['userfile']['tmp_name'][$i],
      'error' => $upload_files['userfile']['error'][$i],
      'size' => $upload_files['userfile']['size'][$i]
);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:54:31+00:00Added an answer on June 2, 2026 at 10:54 am

    You’re overwriting $_FILES['userfile'] on each iteration of the array (which is why only the last file is uploaded).

    Create a new array element each time it loops.

    Also, change your loop to iterate over $upload_files['userfile'] instead of $upload_files['userfile']['name'] as suggested in the above comments 🙂


    Just a pointer – it is better to assign count($upload_files['userfile']) to a variable outside of your for loop. It probably won’t make much difference if your array only has a few elements, but has massive performance benefits when working with large arrays.

    Check out http://www.phpbench.com/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have JavaScript code which copies the value of input file and paste it
I have a php file that contains a form (which contains 2 input boxes
i have an input csv file with columns position_Id, Asofdate, etc which has to
I have written xml file which contains html tags as element like <component> <input
I have created a JAR file in this way jar cf jar-file input-files .
I need an input file stream which would have a bidirectional iterator/adapter. Unfortunately std::ifstream
I have to create a program which requests the user to input file names
How can I input results of a PHP array inside a JS-file? I have
I have progress.js file which has the following code $('#text_area_input').keyup(function() { var text_area_box =$(this).val();//Get
I have a list of file input boxes and I want to know if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.