Ron Ron - 1 year ago 66
jQuery Question

How to handle multiple image upload one by one in php

we have an html form with

<input type="file" name="u_file" class="u_class" id="u_id">
. When user upload an image then it will show in the below div before submitting the form .

<div class="preview-div">


That is when user upload an image then that time we append image to the div by jquery .


$(".preview-div").append(' <img style="" class="img-class" src="'+URL.createObjectURL([0])+'">');


when submit form then it will check

if($_FILES['u_file']['name'] !=""){

$uploadedfile = $_FILES['user_file'];



is the custom function we written .

But the problem is that it will only checking and moving the last image . How to solve this ?.

That is ($_FILES['u_file'] only contain the latest upload image . What we need to do ?We can't use
<input type='file' multiple>

Thank you .

Answer Source

Name your file inputs as a array

<input type="file" name="u_file[]" class="u_class" id="u_id">

$_FILES['u_file'] is a array now

foreach ($_FILES['u_file'] as $file) {


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download