9lessons programming blog
Loading Search
Wall Script
Monday, September 3, 2012

Multiple File Drag and Drop Upload using HTML5 and Jquery.

Are you looking for Drag and Drop multiple file upload using HTML5. Just take a look at this post, I had implemented this system with using jquery and PHP that uploads multiple files into server. This script helps you to enrich your web applications upload system. It works with all modern browsers try live demo and drop files.

Multiple File Drag and Drop Upload

Download Script     Live Demo

Developer
Arun Kumar Sekar
Arun Kumar Sekar

Engineer, Plugin Expert
Chennai, INDIA

Multiple File Drag and Drop Upload this will work in modern browsers like Crome, Firefox and Safari, File uploads happening through ajax
for this I implemented with Form Data and File Reader javascript API.

Requirements
- Jquery (tested with 1.7+)
- HTML 5

How to use
Just include Jquery library and multiupload.js files available in download script.

Javascript Code
All config parameters are required. If you want to allow other files formats, add in valid files variable.
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/multiupload.js"></script>
<script type="text/javascript">
var config = {
// Valid file formats
support : "image/jpg,image/png,image/bmp,image/jpeg,image/gif",
form: "demoFiler", // Form ID
dragArea: "dragAndDropFiles", // Upload Area ID
uploadUrl: "upload.php" // Server side file url
}
//Initiate file uploader.
$(document).ready(function()
{
initMultiUploader(config);
});
</script>

upload.php
Simple PHP code uploading files from client mechanic to server location uploads folder.
if($_SERVER['REQUEST_METHOD'] == "POST")
{
if(move_uploaded_file($_FILES['file']['tmp_name'], "uploads/".$_FILES['file']['name']))
{
echo($_POST['index']); // to validate
}
exit;
}

HTML5 Code
HTML5 drag and drop form.
<div id="dragAndDropFiles" class="uploadArea">
<h1>Drop Images Here</h1>
</div>
<form name="demoFiler" id="demoFiler" enctype="multipart/form-data">
<input type="file" name="multiUpload" id="multiUpload" multiple />
<input type="submit" name="submitHandler" id="submitHandler" value="Upload" />
</form>
<div class="progressBar">
<div class="status"></div>
</div>

Share this post

Comments
{ 112 comments }
Anonymous said...

Awesome. Could you make it into a real file hosting script, where users could upload and get direct download link? generated by md5 hash or something smaller. Thanks, contact me: admin@team-enigma.net!

tinnerdxp said...

I have found another (much worse and old-school) method quite a few years ago, when JQuery wasn't as popular...
In a closed environment you can setup a SFTP server and embed an iframe in the admin area of the site with credentials already embeded, then leave the FTP handling to the browser, that way you can drop any files in the iframe and the browser will upload them into a preconfigured folder.

sathish said...

its really nice work to upload multiple files...

Jagan said...

The most awaited script. Many Thanks

phphunger said...

Amazing arun...it saves lot of time searching individual files..good job...

Anonymous said...

awesome

Petr Jirasek said...

Really nice feature!

Anonymous said...

what if i only want to allow images?

Anonymous said...

you forgot a important thing, the delete button, if someone put the wrong image theres no way to remove it, unless the refresh page

Anonymous said...

Many Thanks arun...

Anonymous said...

Can add progress bar and percent upload? :)

Naveen Sridhara said...

real good,thanks for sharing great work

Saphaloud said...

input type="file" multiple="multiple" name="file[]" works well too

Legend said...

if the file name is same it over writes it how to avoid???

My Self said...

good job...

Anonymous said...

How can I add a progress bar ???

oeMeo said...

It only shows uploading. Where does it store the images?

Anonymous said...

And isnt IE a modern browser?

Jossyl said...

well i'm trying to configure the multiupload.js with this on _preview = function(data)
var sampleIcon = 'img src="images/image.png" tag a id="del" href="" border="0" tag img src="images/trash.png" end tag a';

for delete just pick one and most don't upload it
thanks for the nice post but i can't delete yet :/

Kevin Orand said...

Very, very good tutorial, I like!!

Anonymous said...

Last time I made same thing in ASP.NET MVC with a little feature more.

I show the images when someone upload them live without any refresh. Can you please make them here in php too.

The plugin I use is located here https://github.com/malsup/form

Vijay lathiya said...

thanks srinivas, u r doing good work for all developers.

Dhrumil said...

That is fine and works good...but Arun I am looking to upload from both local drive and from another website, which means I can drag image from another tab of same browser or another browser and drop in there to upload SAME AS imgur(.)com...try this site to upload from both local drive and another website. Is it possible? do you know how to do so? Please reply me if you have any idea.

BlueHeart said...

Thank you so much

Karthik Naidu said...

Hey you need to add remove button to each file, as well it is allowing the duplicate selection of same image. please do check these.

Anonymous said...

it is possibile to integrate whit joomla?

Anonymous said...

It is possible to integrate with joomla?

Arun said...

Thanks guys, i will upgrade this ASAP with delete and progress status.Keep watching

David said...

Thank you for your good tutorial!

Anonymous said...

Great Work !

Aman Tilak said...

Cool job but not working in ie8 ..is there any solution..

Aman Tilak said...

what changes i should do if i want to upload doc file , pdf files or zip files.....
Thank you

Anonymous said...

How to create a unique URL for every file uploaded?

Anonymous said...

How can I call another function after all the files were uploaded?

Vijaya Kumar said...

nice work

Liju Philip said...

Thanks for sharing. Much appreciated.

Cakephp Developers said...

Also saying that its not works proper in IE8. If any problem in your coding or mine process.

installer said...

good work...

Anonymous said...

When will the update be ready to download ?
(Update with deletebutton and progressbar)

Qamil said...

nice script but css needs some improvements :S

Anonymous said...

nice

Anonymous said...

nice

Anonymous said...

Please I need help. I did all what your tutorial says. If I upload an image it doesnt stop to upload

Please help

Anonymous said...

Please help.

How can I add an Database Input Query?

Please answere.

Thanks

Anonymous said...

i added zip/tar to the allowed files but i cant upload it. Please help

Ravi said...

Really Helpful post..Thanks

Anonymous said...

Is it really working..? Are you sure buddy...??

Here it only shows uploading. Where does it store the images?

Amit sarwara said...

yeah..... this is really awesome tutorial....thanks for sharing this...

tricktodesign said...

huuuuummmmmmmmmmm...................Thanks for sharing this man...Really use full for me....Thanks a lot again....

Anonymous said...

not working with IE7. any compatability issues

Niraj Dewangan said...

I have problem, i have uploaded photo and modify your code:

if(move_uploaded_file($_FILES['file']['tmp_name'], "uploads/".$_FILES['file']['name'])){
echo($_POST['index']);
}

to the following:

if(copy($_FILES['file']['tmp_name'],"uploads/".$_FILES['file']['name']))
{
$temp="uploads/".$_FILES['file']['name'];
$insert="insert into reg values('NULL','$temp') ";
$res=mysql_query($insert);

echo($_POST['index']);
}
In database the image path is store but it store each time all the previous uploaded image path

Niraj Dewangan said...

Arun you have done a good job. please help me.

Niraj Dewangan said...

hey arun i got the solution just place the

if(this.all.length = 0){
window.location.reload(); }

in the line number 103 of multiupload.js.. its working

Anonymous said...

Is there a way to limit the total filesize?

Naresh said...

Excellent script boss...

Anonymous said...

Aman, here's a list of mime types:

http://www.hansenb.pdx.edu/DMKB/dict/tutorials/mime_typ.php

In index.php, just add 'application/pdf' and 'application/zip' and (I think) 'application/octet-stream' to the "support:" line.

Sandeep Verma said...

Thanks .. very useful for file upload .. good job ;)

Anonymous said...

This seems like a very daft question, so apologies for asking...

When I press 'upload', I'd like to move on to the upload page itself rather than staying on the same page. How?

Anonymous said...

I removed the if in the move uploaded file, and then it wont upload anymore whats wrong if i remove it?

vijoy sasidharan said...

nice job arun..can i upload mp3 files using this upload form..???

Anonymous said...

GREATE JOB SIRINVAS , CAN YOU ADD RESIZING WITH THIS UPLOAD FORM PLEASE

Agung Yudha Berliantara said...

Wow,
nice and simple
thx so much brother :)

hagbard celine said...

Great script - one thing I've found is that if a user hits 'upload' again, it uploads any files that were dropped in, even though their progress bars and such are gone. Is there a way to clear out the queue once it's done, or preferably have each item remove itself from the queue once its upload/success has been triggered?

Fabio said...

How to accept all types of files?

AD said...

This works well. I am unable to insert the file information into the database.I am trying to connect the to db before the if st. Any help is appreciated. Thanks.

AD said...

how do i do a database insert? It is not inserting if i put in php db insert. Thanks for your help.

innuendo said...

No funciona en internet explorer, ayuda porfavor

Ali said...

Very useful upload example. Thanks.

Anonymous said...

I have been looking for a useable version of this for ages! thank you sooo much!

PS - thanks to whoever explained 'mime types'

This is the way to be able to upload any file type.

Michel said...

I have a problem with special characters..

füder_box.jpg => füder_box.jpg / füder_box.jpg :-(

zakir hossain said...

awesome code ever... lot of thank ..

zakir hossain said...

it is not working in IE8 too, please update for IE version otherwise unable to use it.

Blog do Miranda said...

Congratulations, this is the best uploader.

Noor Rizvana said...

how can i make this photos name and destinations to be recorded in mysql table...please help....its urgent

Brian Babu said...

Yes it did work... and looks pretty good but i seem to have problems uploading audio and video files...even after adding the MIME types to the support variable...!! this the support variable i have with me...!

support : "image/jpg,image/png,image/bmp,image/jpeg,image/gif,image/tiff,application/pdf,audio/mp3,video/mp4,video/avi", // Valid file formats

Is there any file size restriction put in the script....if so please advice on how to change it...! Thanks!! :)

Anonymous said...

yes its very good.. thanks

Parody-42 said...

Code not available anymore :(

Helder said...

Not work in Internet explorer why?

anu said...

can anyone help me to upload a complete folder plesae???

Anonymous said...

can anyone help me to upload directories, I mean complete folder?

Anonymous said...

can anyone help me to upload multiple file in jsp

Anonymous said...

any way to remove file limit

Anonymous said...

If it keeps uploading check the authorisaton for URL defined in the "uploadUrl". Also make sure the defined path in "upload.php" where the files will uploaded is correct and writable.

Anonymous said...

Great code. Does somebody know when the update will be up and runnnig?

Jeff Solomon said...

Has anyone been able to figure out how to specify file size max? By default it doesn't seem to handle large files (i.e. 2.5MB or greater)

Anonymous said...

Hi,

Good Job Arun. Its really awesome lib.
I have one question. Can I put multiple instances of it in my single page. I need multiple drag and drop areas in my single page.
Please guide me.
Thanks

Anonymous said...

Its not working into IE and safari if you have any version or any modification please share with us.
We appreciate your help
Thanks.

Anonymous said...

how about multiple uploading of mp3 files? can you help me with this?

Anonymous said...

Is there a way to limit the amount of files to be uploaded?

Vadim Axelrod said...

Line 48 in multiupload.js should be:

$("#"+this.config.dragArea).append(html);

Royal Guardian said...

Thanks.
But if you explained the multiupload.js would have been better.

Marian said...

I have it set to save to a directory which has proper permissions, etc. but the files are not actually being stored there - or anywhere. This ALMOST works....ugh.

ChaisoftNet said...

Valid file formats i want to upload file.php ? can

filipe maia mandelli said...

how can i remove a file from FileList?

Anonymous said...

hi,

Thanks guys, i will upgrade this ASAP with delete and progress status.Keep watching

How to accept other formats (doc, pdf) in Multiple File Drag and Drop Upload using HTML5 and Jquery.?

support : "image/jpg,image/png,image/bmp,image/jpeg,image/gif,doc/doc,pdf/pdf", not work

Thanks

Louk Rath said...

I can't upload with google chrome. Please help...

Bunty Roy said...

Nice one. I have use it several time but it does not work in ie7 can you give any suggestion.

muhammadishaq ansari said...

Hi, I am using this drag n drop. This is not working with full window or maximize window.
When i restore window then it works..
Please let me if you have any solution

Thanks
Ishaq

KHEM CS said...

thanks

KHEM CS said...

thanks

saravanaa karthick said...

hi.please heip how to upload mp3 files using this form

Anonymous said...

how I can decide where is upload path? can I add input fild where i can set directory name to upload.

Pls help me

Brent Kilner said...

Thank you very much. it is a very good script

Brent Kilner said...

Thank you very much for this code

Brent Kilner said...

Thank you very much. it is a very good script

ajay gangarde said...

hii i have problem that i want to use passed id in the same page like in url of uploaded directory which passed from last page..

images/users/2/".$_GET['galTitle']."/images/".$_FILES['file']['name'];

Anonymous said...

Hi,

I try to add a choosing folder with a "select" to your script but I don't know how to receive it with a $_POST variable in the file upload.php
and uplaod the pictures in the folder choose by the user like :

upload/player/
upload/press
upload/match/

regard's

umar said...

actually I am storing the three Values in Data Base,it successfully storing date, path but not storing the gallery id, here is my code I am using




I have already spent two days on it but all in Vain
Could any body please solve my problem. thanks in advance

Anonymous said...

Is it possible to upload .html files?

I tried adding text/html in the file formats but didnt work.

Anonymous said...

Great starting point for developing a more detailed up-loader. Thanks so much for sharing!

Sumanth Sharma said...

Can any one say me how to limit the number of files to 5 , if user uploads 6 it shouldnot accept

Sumanth Sharma said...

can any one say me how can i limit the number of files uploaded to 5 , if user upload 6 , the drag and drop should not accept

Post a Comment