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 8952575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:54:17+00:00 2026-06-15T13:54:17+00:00

I have a form which can have multiple file inputs (one file per input,

  • 0

I have a form which can have multiple file inputs (one file per input, not multi select).

When I submit the form, how do I get an array of all input[type="file"] contents and use FileReader to look at the file sizes before they are uploaded, and prevent it if any of the files is too large?

$('#MyForm').submit(function() {

});

I can’t figure this out at all from what limited FileReader documentation I can find. Or not get it to work, anyway…

  • 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-15T13:54:18+00:00Added an answer on June 15, 2026 at 1:54 pm

    The problem was the way in which I was trying to select the files from the file input with jQuery. Here are some example solutions:

    If you have one file input, and the user can only select a single file:

    // Get the file
    var file = $('input[type="file"]').get(0).files[0];
    
    // File size, in bytes
    var size = file.size;
    

    If you have one file input, with multiple file select:

    // Get an array of the files
    var files = $('input[type="file"]').get(0).files;
    
    // Loop through files
    for (var i=0; file = files[i]; i++) {
    
        // File size, in bytes
        var size = file.size;
    }
    

    If you have multiple file inputs, with multiple file select:

    // Loop through each file input
    $('input[type="file"]').each(function(i) {
    
        // Get an array of the files for this input
        var files = $(this).get(0).files;
    
        // Loop through files
        for (var j=0; file = files[j]; j++) {
    
            // File size, in bytes
            var size = file.size;
        }
    });
    

    Once you have the File object, here are the properties you have access to (apart from size):

    https://developer.mozilla.org/en-US/docs/DOM/File#Properties

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

Sidebar

Related Questions

I have a php file which has one form and 2 submit buttons, onclick
I have a form in which can be a few lines of inputs the
I have a form with input field which can be accessed like var algorithm
I have a form which I need to POST to multiple scripts. How can
I have mock-up of a form, in which there's a file input element that
I have a form which uploads multiple file fields into a db using codeigniter.
I have a form which users can add controls to and when they right
I have a form where there are 6 items, each of which can be
i have a form, which you can pretend is laid out like Windows Explorer:
I have the following form, which I have reduced as much as I can,

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.