Multiple File Upload PHP & Ajax Plugging


frontend


<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

</head>

<body>

    <form id="frm" enctype="multipart/from-data">

        <input type="file" name="upload_file[]" multiple><br><br>

        <button type="button" onclick="sub();">SUBMIT</button>

    </form>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<script>

    function sub(){

        var upload = new FormData(frm);

            console.log(upload);

                $.ajax({

                    data : upload,

                    type : "POST",

                    url : "index_b.php",

                    processData : false,

                    contentType : false,

                    success: function (res) {

                        

                    }

                })

    }

</script>

</body>

</html> 


Backend



<?php
$conn = mysqli_connect("localhost","root","","fileupload_3") or die ("connection faield");

for ($i=0; $i <count($_FILES['upload_file']['name']) ; $i++) { 
    move_uploaded_file($_FILES['upload_file']['tmp_name'][$i],"img/".$_FILES['upload_file']['name'][$i]);
}
$convert = implode(" + ",$_FILES['upload_file']['name']);
$query = "INSERT INTO tab (file) VALUES('$convert')";
$fire = mysqli_query($conn, $query);
if ($fire) {
    echo "File has been Uploaded";
}else{
    echo "Uploading failed something wrong with internet";
}
?>

Comments

Popular posts from this blog

C.R.U.D Oparetion in (PHP Code)

Search Dropdown - jQuery

Laravel - Dependent Drop Down Using Ajax