PHP 8 Multiple File Upload using Ajax Example Tutorial

Jun 25, 2022 . Admin

Hello dev,

Today, I will let you know example of PHP 8 Multiple File Upload using Ajax Example Tutorial. this example will help you PHP 8 Ajax Multiple File Upload Example. you will learn How to upload Multiple files with jQuery AJAX and PHP 8. we will help you to give example of AJAX Image and File Upload in PHP 8 with jQuery.

This article will give you simple example of PHP 8 Upload multiple files jQuery Ajax

So, let's see bellow solution:

<!DOCTYPE html>
<html lang="en">
    <title>PHP 8 Multiple File Upload using Ajax Example Tutorial</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="">
    <script src=""></script>
    <div class="container mt-5">
        <div class="row">
            <div class="col-md-12">
                <div class="card m-auto w-75">
                    <div class="card-header text-center text-white bg-dark">
                        <h4>PHP 8 Multiple File Upload using Ajax Example Tutorial -</h4>
                    <div class="card-body">
                        <div class="alert alert-success alert-dismissible" id="success" style="display: none;">
                            <button type="button" class="close" data-dismiss="alert">×</button>
                                File uploaded successfully
                        <form id="submitForm">
                            <div class="form-group">
                                <label><strong>Select File : </strong><span class="text-danger"> *</span></label>
                                <input type="file" class="form-control" name="multipleFile[]" id="multipleFile" multiple>
                             <span id="error" class="text-danger"></span><br>    
                            <div class="form-group d-flex justify-content-center">
                                <button type="submit" name="upload" class="btn btn-primary">Upload</button>
    <script type="text/javascript">


            $('#multipleFile').change(function () {
                var ext = this.value.match(/\.(.+)$/)[1];
                    switch (ext) {
                        case 'txt':
                        case 'pdf':
                        case 'docx':
                        case 'csv':
                        case 'xlsx':
                            $('button').attr('disabled', false);
                        $('#error').text("File must be of type txt,pdf,docx,csv,xlsx.");
                        $('button').attr('disabled', true);
                        this.value = '';

            $("#submitForm").on("submit", function(e){
                    url  :"store.php",
                    type :"POST",
                    contentType : false, // you can also use multipart/form-data replace of false
                    processData : false,
                    data: new FormData(this),
    $sernamename = "localhost";
    $username    = "root";
    $passoword   = "";
    $databasename= "store";
    $con = mysqli_connect($sernamename, $username,$passoword,$databasename);

    if ($con->connect_error) {
        die("Connection failed". $con->connect_error);

    if (!empty($_FILES['multipleFile']['name'])) {
        $multiplefile = $_FILES['multipleFile']['name'];

        foreach ($multiplefile as $name => $value) {
            $allowFile = array('txt','pdf','docx','csv','xlsx');   
            $fileExnt = explode('.', $multiplefile[$name]);

            if (in_array($fileExnt[1], $allowFile)) {

                if ($_FILES['multipleFile']['size'][$name] > 0 && $_FILES['multipleFile']['error'][$name]== 0) {
                    $fileTmp = $_FILES['multipleFile']['tmp_name'][$name];
                    $newFile =  rand(). '.'. $fileExnt[1];
                    $target_dir = 'uploads/'.$newFile; 

                    if (move_uploaded_file($fileTmp, $target_dir)) {
                        $query  = "INSERT INTO user(file) VALUES('$newFile')";
                        mysqli_query($con, $query);

It will help you...
#PHP 8