How to upload multiple files in php with add and remove options?

1 Answer(s)

Hello, thanks for your questions,
I will show you how to upload multiple files in PHP with add and remove/delete options using PHP, javascript, and jquery. I have generated my personal PHP script which is very easy to understand and setup is also easy for any developers or users. You just need to follow the steps below.

I have fixed the add and delete/remove options also for multiple files upload in PHP. You can see the demo at the bottom of the page. Let’s start the tutorial.

Follow the steps for upload multiple files in php with add and remove options

Step 1: Create one “index.php” file and make one folder named “uploads” in your server
First of all, you need to create one file name “index.php” and create one folder name “uploads”.
Uploads folder is used for store all the uploaded files.

Step 2: Copy the below code and paste in “index.php”
The second step is you just need to copy the below code and paste it in your “index.php” file because This code is created by me and I have used the jquery for add new files and remove/delete selected files.
That’s it you can now execute the code and upload multiple files in PHP with add and remove/delete options using PHP, javascript, and jquery.


ini_set("error_reporting", 1);



for ($i = 0; $i < count($_FILES['files']['name']); $i++)


if ($_FILES["files"]["size"][$i] < 1000000) // Check File size (Allow 1MB)


$temp = $_FILES["files"]["tmp_name"][$i];

$name = $_FILES["files"]["name"][$i];





if($i == 0){ $err = "File uploaded successfully"; $cls = "success"; }





$err = "File size is more than 1MB";

$cls = "danger";








body{ font-family:sans-serif; }

table, th, td {

border: 1px solid black;

border-collapse: collapse;


.success{ color: green;}

.danger{ color: red;}





<form method='post' enctype='multipart/form-data'>

<table id="table" width="50%">


<tr class="text-center">

<th colspan="3" style="height:50px;">Mutiple File Upload Script</th>




<tr class="add_row">

<td id="no" width="5%">#</td>

<td width="75%"><input class="file" name='files[]' type='file' multiple /></td>

<td width="20%"></td>





<td colspan="4">

<button class="btn btn-success btn-sm" type="button" id="add" title='Add new file'/>Add new file</button>



<tr class="last_row">

<td colspan="4" style="text-align:center;">

<button class="btn btn-primary submit" name="btnSubmit" type='submit'>Upload</button>







<h2 class="<?php echo $cls; ?>"><?php echo $err; ?></h2>


// Validation


var file_val = $('.file').val();

if(file_val == "")


alert("Please select at least one file.");

return false;



$('form').attr('action', 'index.php');


// Append new row

$('#table').on('click', "#add", function(e) {





// Delete row

$('#table').on('click', "#delete", function(e) {

if (!confirm("Are you sure you want to delete this file?"))

return false;






I hope you will like this tutorial and enjoyed it. If you have any questions then ask me again.

Default Answered on September 30, 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.