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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:54:33+00:00 2026-06-11T01:54:33+00:00

I would like to create a multifile file uploader using jQuery. Below is the

  • 0

I would like to create a multifile file uploader using jQuery.

Below is the code I am working with. I am just trying to abstract out the essentials to uploading multiple files at once using jQuery (and File API) and PHP. If anyone has a simplified answer feel free to share or offer suggestions.

Right now this code works to upload the images(kinda), however. There are issues:

  1. Even after selecting more than one file, only one file uploads to the directory
  2. The form changes the page upon submit

Here is the js/jquery I am working with:

function html5Upload($form) {
    file = $form.data('input');
    if (file) {
        var fd = new FormData();
        fd.append($form.find(selector).attr('name'), file);
        //get other form input and append to formData
        $form.find(':input').each(function () {
            if (this.type != 'file') {
                fd.append($(this).attr('name'), $(this).val());
            }
        });

        //Upload using jQuery AJAX
        jqxhr = $.ajax({
            url: $form.attr('action'),
            data: fd,
            cache: false,
            contentType: false,
            processData: false,
            type: 'POST',
            success: function () {
                alert("Images Uploaded!");
            }
        });
    }

    $form.remove();
}


$('form').submit(function (event) {
    event.preventDefault();
    html5Upload($('form.mupload'));
    return false;
});

HTML

<form class="mupload" action="upload.php" method="post" enctype="multipart/form-data">
    <input type="file" name="userfile" class="fileUpload" multiple>

    <button type="submit">Upload</button>
</form>

PHP

/*
Easy PHP Upload - version 2.32
A easy to use class for your (multiple) file uploads

Copyright (c) 2004 - 2010, Olaf Lederer
*/
include("easy_upload/upload_class.php");

$upload = new file_upload();

$upload->upload_dir = 'uploads/';
$upload->extensions = array('.png', '.jpg', '.zip', '.pdf'); // specify the allowed extensions here
$upload->rename_file = true;


if(!empty($_FILES)) {
    $upload->the_temp_file = $_FILES['userfile']['tmp_name'];
    $upload->the_file = $_FILES['userfile']['name'];
    $upload->http_error = $_FILES['userfile']['error'];
    $upload->do_filename_check = 'y'; // use this boolean to check for a valid filename
    if ($upload->upload()){

        echo '<div id="status">success</div>';
        echo '<div id="message">'. $upload->file_copy .' Successfully Uploaded</div>';
        //return the upload file
        echo '<div id="uploadedfile">'. $upload->file_copy .'</div>';

    } else {

        echo '<div id="status">failed</div>';
        echo '<div id="message">'. $upload->show_error_string() .'</div>';

    }
}
  • 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-11T01:54:35+00:00Added an answer on June 11, 2026 at 1:54 am

    I’ve seen a few potential problem so far:

    1. Only one file uploaded.

      • For multiple file upload, I think the name attributes of the file input should be something like userfiles[]. This way it will not be overwritten. FYI: if two HTML input have the same name without [], only the latter will be send over the request. [] can also be used to send any data that have multiple values such as select (think of Array, and it is represented as array in $_POST).
      • I don’t really know your upload handler, are you sure it can handle multiple file upload?
    2. I guess you included the script tag before the form? Try put the event code inside jQuery domReady like so

    .

    $(function() {
         $('form').submit(function (event) {
            event.preventDefault();
            html5Upload($('form.mupload'));
            return false;
        });
    });
    

    You might want to check this issue first.

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

Sidebar

Related Questions

I would like to create this shape using just css. I am pretty sure
I would like to create set of strings and below is the only limitation.
I would like to create a class that describes a file resource and then
I would like to create a .js file that has multiple submit buttons lined
I neeed to create multiple versions of my project using configuration just like we
I would like to create a class whose methods can be called from multiple
I need to setup multiple queues on an exchange. I would like to create
i would like create a array of structure which have a dynamic array :
I would like to create a c++ type that mimic the build-in type exactly.
I would like to create a json object to send as a post array,

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.