S Image Preview Before Upload In jQuery Bootstrap Example

S Image Preview Before Upload In jQuery Bootstrap Example

In this post we will give you information about S Image Preview Before Upload In jQuery Bootstrap Example. Hear we will give you detail about S Image Preview Before Upload In jQuery Bootstrap ExampleAnd how to use it also give you demo for it if it is necessary.

Today, Laravel share one helpfull tutorials about jquery and bootstrap. in this tutorials we are show you how to show image preview before upload.

We are need some time this type functionality in frontend site which you want to show image preview before it upload in server. resently we are working on one laravel application and we are need this so we are make one simple script for it using jquery and bootstrap. and we are finaly done this with jquery and bootstrap.

Here, we are always share our and example which we are facing in our devloping mode and when we are find finaly solution about it the we are also share with you.

You can try this example with bootstrap because we are using bootstrap for fine layout.

Step : 1 HTML look like

<!DOCTYPE html>
	<title>Show Image Preview Before Upload</title>
	<link rel="stylesheet" type="text/css" href="#">
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7https://onlinecode.org/js/bootstrap.min.js"></script>
	<div >
	    <div >    
	        <div >  
	            <div >
	                <span >
	                    <button type="button"  style="display:none;">
	                        <span ></span> Clear
	                    <div >
	                        <span ></span>
	                        <span >Browse</span>
	                        <input type="file" accept="image/png, image/jpeg, image/gif" name="input-file-preview"/>

Step : 2 CSS look like

Then add some css copy following and add in your css file.

.image-preview-input {
    position: relative;
	overflow: hidden;
	margin: 0px;    
    color: #333;
    background-color: #fff;
    border-color: #ccc;    
.image-preview-input input[type=file] {
	position: absolute;
	top: 0;
	right: 0;
	margin: 0;
	padding: 0;
	font-size: 20px;
	cursor: pointer;
	opacity: 0;
	filter: alpha(opacity=0);
.image-preview-input-title {

Step : 3 jQuery look like

The finaly add following jQuery in js file.

$(document).on('click', '#close-preview', function(){ 
    // Hover befor close the preview
        function () {
         function () {

$(function() {
    // Create the close button
    var closebtn = $('<button/>', {
        text: 'x',
        id: 'close-preview',
        style: 'font-size: initial;',
    closebtn.attr("class","close pull-right");
    // Set the popover default content
        title: "<strong>Preview</strong>"+$(closebtn)[0].outerHTML,
        content: "There's no image",
    // Clear event
        $('.image-preview-input input:file').val("");
    // Create the preview image
    $(".image-preview-input input:file").change(function (){     
        var img = $('<img/>', {
            id: 'dynamic',
        var file = this.files[0];
        var reader = new FileReader();
        // Set preview image into the popover data-content
        reader.onload = function (e) {
            img.attr('src', e.target.result);

Now we are ready to run our example so run bellow command ro quick run:

If you face any problem then please write a comment or give some suggestions for improvement. Thanks…

Hope this and post will helped you for implement S Image Preview Before Upload In jQuery Bootstrap Example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

3  +  5  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US