File Upload Part of a Form Bootstrap

The input type file

Amid the other input types like text, password etc. the file input type allows creating a form element that enables users to select a file to upload in the Bootstrap framework, which is basically an HTML tag.

This is just the thing of specifying HTML tag:

For instance:


However, designing and changing the text and design of file upload button is a tiresome job. This is generally desired to match upload file button with the remainder of course fields in a web page, otherwise, it looks ugly and unmatched. This is not provided in the default classes by Bootstrap. Y'all may use your own or tertiary political party solutions for that.

Following is a guide to setup Bootstrap file upload field if you are working in the Bootstrap framework and as well included jQuery library.

The guide is using a plug-in, bootstrap-filestyle, which is bachelor at Github website (credit link is given below). Let me first from simple to more fashionable examples with icons in upload form controls to a complete form demo.

Afterward demos, you can run across a footstep past step guide to prepare upwardly this plug-in. The terminal demo is a sign-up course with PHP code to show you how to upload files while using this plug-in.

A simple file control push

In the following demo, bootstrap-filestyle plug-in is used to create a file option field. You accept to include four dependency files in the <head> section for these demos to works (see the setup guide at the bottom role).

Come across the demo and code by clicking the link or image below:

Bootstrap file upload simple

Come across online demo and lawmaking

The button is initialized via data attribute:


An upload file control with dissimilar text and icon via data attribute

This control is using a unlike text "Select a file" along with an icon while text path field is disabled. See the demo and code online:

file upload change text

See online demo and code

Bootstrap button style for file upload button example

The following is a demo of Bootstrap styled push button, where y'all tin can employ the same class names as in Bootstrap buttons.

Bootstrap file upload

See online demo and code

You lot tin can encounter, three upload file controls with three dissimilar styles and text. This time, the buttons are initiated by jQuery/JavaScript. The text and push proper name that represents the button style is specified in the jQuery department, just higher up the </body> tag.

The code:

The jQuery lawmaking


A demo of different icon

In this Bootstrap / jQuery upload file button, a different icon is used than above examples. You may set the icon in the JavaScript section by using the iconName option, as shown below:

Bootstrap file upload icon

See online demo and code

You tin run across the demo page's code section, the glyphicon glyphicon-file is used in the options part afterward initiating the push. Apart from that, push text and push button proper noun are as well specified.

The markup:

The jQuery code:


An HTML file input push button with articulate pick

The plug-in also includes the option to clear the selected file in the textbox area by clicking a "clear the file name" text. See a demo online:

Bootstrap upload file clear

See online demo and code

The post-obit code is used to create this button, including JS part:

The Markup:

The jQuery lawmaking:


A multiple file selection choice for upload push demo

You may use the multiple attribute in the input type file tag to let users selecting multiple files by pressing the control or shift keys with mouse etc.

The following demo shows selecting the multiple files from the computer or system. After you choose multiple files you can also clear the selection by using the clear push button. See online:

Encounter online demo and code

The following code is used for markup and jQuery:

The markup:

The jQuery:

An example of file count

Y'all can besides testify file count for the multiple file selection upload buttons. For that only use the multiple attribute in the input type file tag and utilize input: false option in the jQuery section. See the demo:

jQuery upload file count

Encounter online demo and code

The following code is used:

The markup:

The jQuery:

Setting upward Bootstrap file upload plugin for your project

Follow these steps to set this great plug-in to create the beautiful and customized Bootstrap / jQuery based file upload buttons:

Footstep one:

Include the Bootstrap framework files from CDN or host it at your own.

You demand both CSS and JavaScript files east.g.:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/iii.3.v/css/bootstrap.min.css"  crossorigin="bearding">

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.five/js/bootstrap.min.js"  crossorigin="anonymous"></script>

Step two:

Y'all also need to include jQuery library, for example:

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

Step iii:

Include Bootstrap FileStyle plug-in file:

bootstrap-filestyle.min.js

Y'all may get it from the plug-in site (link given below).

I have placed it in the JS binder for the demos, and used this line to refer:

<script type="text/javascript" src="js/bootstrap-filestyle.min.js"> </script>

Step 4:

Start creating buttons every bit shown in the above examples by using markup and jQuery.

Credits:  The plug-in website

A Bootstrap class with input file and PHP upload script

The following is a full general sign-up class created by using Bootstrap framework that also has input type file command past using above plug-in. The demo likewise includes the PHP lawmaking to upload the file to the server.

See the demo online which is followed by a piddling description to gear up this upward at your server:

jQuery upload file form

Come across online demo and code

Follow these steps to learn how this form will work:

Footstep one:

The grade is created by using the Bootstrap framework. For input type file customization, the to a higher place plug-in is besides included in the head section. Following libraries are included in the caput section:

<!DOCTYPE html>

<html>

<caput>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"  crossorigin="anonymous">

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/three.3.v/js/bootstrap.min.js"  crossorigin="anonymous"></script>

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.one/jquery.min.js"></script>

<script blazon="text/javascript" src="js/bootstrap-filestyle.min.js"> </script>

Step 2:

Following custom CSS for the grade controls is used (skip this to learn file uploading just) or use default or your own scheme:

Pace three:

Creating the form that uses Bootstrap classes along with Bootstrap Fileupload plug-in's options in the <body> section.

To upload file, following <course> tag is used:

<form class="form-horizontal" part="form" activity="procedure.php" method="mail" enctype="multipart/form-data">

The form volition exist submitted to process.php file that should contain the script for managing uploaded file as well as saving the information in the database.

For this demo, I am just using the PHP upload script in the process.php file(given beneath).

Y'all can see the complete form code in the demo page, after the <torso> opening tag.

Step four:

The PHP code to upload the file placed in procedure.php file:

Note that, there must be uploadedimages (or change it every bit y'all want) destination binder created before running this code. Also, the sentfile is the name of file Upload input field in the form section.

colegaver1988.blogspot.com

Source: https://www.jquery-az.com/bootstrap-jquery-input-type-file-upload-buttons-and-script/

0 Response to "File Upload Part of a Form Bootstrap"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel