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

  • Home
  • SEARCH
  • 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 8515269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:06:06+00:00 2026-06-11T05:06:06+00:00

I have a file input that selects multiple files that looks like this: <input

  • 0

I have a file input that selects multiple files that looks like this:

<input type = 'file' name = 'file[]' id = 'file' class = 'file' multiple = 'multiple' />

When the user chooses a file (or files), using Javascript I update the id and class to ‘oldFile’, then prepend another file input, but with file2[] instead of file[]. This happens as long as the user keeps picking files. Then, when the user submits the form the files get sent to my PHP script. I have tried two ways of counting the files, shown below.

The first is a simple

$files = count($_FILES);

The second is

$f = 0;
foreach($_FILES as $b)
{
    $f++;
}
$files = $f;

However, when I select files in a certain order, it returns an incorrect count.

If I select two files, then one file, then two files and submit the form, it says I submitted 4 files.

If I select two files then one file, it correctly says 3 files.

Any idea what the problem could be (not sure if I’m making sense)?

  • 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-11T05:06:08+00:00Added an answer on June 11, 2026 at 5:06 am

    PHP’s $_FILES is a bit wonky when you use array-based file upload names as you are. The structure created, in that case, is actually

    $_FILES = array(
       'name' => array(
          0 => 'name of first file'
          1= > 'name of second file'
          etc...
       'type' => array(
          0 => 'type of first file',
          1 => 'type of second file'
       etc..
    );
    

    meaning that you’ll get a constant count($_FILES) matching the number of fields tracked within an upload. To get an accurate count of how many files were uploaded, you need to count one of the sub-keys, eg.

    count($_FILES['name']);
    

    Don’t ask me why it was done this way. PHP’s design is already stupid enough, and this just one of many examples proving its bedrock stupidity.

    A more sensible/sane designer would have used

    $_FILES = array(
       0 => array(... all data about file #1),
       1 => array('... all data about file #2),
       etc...
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that allows for multiple file uploads. <input name=uploadedfile[] type=file multiple=true/>
I have that basic, well known multiple file upload form. Something like that... <input
I'm generating an html file which looks like: <tr id=ID001 property1=PROPERTY001><td><input type=checkbox name=row_checkbox_ID001></td><td>...</td><td>...</td></tr> <tr
I have created a JAR file in this way jar cf jar-file input-files .
if i have one form that include some input, textarea, select, and multiple file.
I have a string that contains multiple parameters delimited by #, like this :
I have a input type=file tag in my html which allows user to select
Please help with the following: I have an input file that is quite heterogeneous
I have a program that reads input from a file. I am trying to
I have a php file that contains a form (which contains 2 input boxes

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.