jquery drag and drop file upload

How we can create a drag and drop upload field for uploading images? Solution: See this jQuery Drag and Drop File Upload, Bootstrap Image Upload, and Preview.

Previously I have a custom file upload input, but this is an image upload field with drag and drop feature. Basically, this type of upload field contains an area where you can upload files by click on mouse over the field or also you can drag and drop files to the field. After selecting the file you will show the file name, or if it is image then you will see the preview of image.

Today you will learn to create Bootstrap Image Upload and Preview. Basically there is a field for upload file, you have to click over the select field for select and upload the image. Also, you can drag and drop the image file for selecting and see the preview. This program is for uploading image because it will show the image’s preview, But you can use this program to upload any type of file after some modifications.

So, Today I am sharing jQuery Drag and Drop File Upload. There I have used bootstrap to create a responsive layout and pre-build styling & functions. And for the important functioning, I have used jQuery and as we know it is a JS library that’s why I am putting this in the JavaScript category.

If you are thinking now how this image upload field actually is, then see the preview given below.

Preview Of Bootstrap Image Upload and Preview Program

See this video preview to getting an idea of how this drag and drop upload program looks like.

Live Demo

Now you can see this visually, also you can see it live by pressing the button given above. If you like this, then get the source code of its.

You May Also Like:

jQuery Drag and Drop File Upload Source Code

Before sharing source code, let’s talk about it. First I have created the layout using Bootstrap grid layout and pre-built class and ID names. In the form field, I have used a special attribute that is required for uploading a file. I have used enctype="multipart/form-data" command in the form tag (info). In the HTML file, I have created all the elements like upload field, button, and text, etc which are based on bootstrap. Also in the HTML file, I have linked other files like CSS, JS, and Bootstrap, Jquery’s CDN link.

Now using CSS I have a little bit styled the elements like dotted border on the field, placing text, etc as you can see in the preview. There is fewer lines of CSS codes because the program is based on bootstrap and it is a library of HTML CSS JS. Using CSS I have modified the color of the upload button and basic margin, padding.

jQuery handling here an important feature of the program. It shows a preview of the image with a 200px width after selecting the image. Also, there is a reset feature, after selecting the image you can reset the form for starting over again. The drag and drop is based on Bootstrap’s JS library, we just have to use some pre-built class/ID names like dropzone, dragover, etc

Left all other things you will understand after getting the codes, I can’t explain all in writing. For creating this program you have to create 3 files. First for HTML, second for CSS, and the third for JavaScript. Follow the steps to creating this without any error.

index.html

Create an HTML file named ‘index.html‘ and put these codes given below.

style.css

Now create a CSS file named ‘style.css‘ and put these codes given here.

function.js

The last step, create a JavaScript file named ‘function.js‘ and put the codes.

That’s It. Now you have successfully created jQuery Drag and Drop File Upload, Bootstrap Image Upload, and Preview Program. If you have any doubt or question comment down below.

Thanks For Visiting, Keep Visiting.

6 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here