Monday, 22 September 2014

How to Preview Uploaded Image before Upload To Server

Here i will explain how to preview the image file before uploaded to server. When we upload any image file to server or to any file location.It is not possible to find out the write selection you have choose which u want to upload to server. By this example we are able to preview the selected image file before upload and choose the correct selection which u want to upload.

Take file upload control to browse the selected image file which you want to upload to server.By using of jquery file we are able to preview the image before upload to the server.
Download Code

Html Code:
<style type="text/css">
    font-family: Arial;
    font-size: 10pt;
    filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);
    min-height: 400px;
    min-width: 400px;
    display: none;
    .auto-style1 {
        text-decoration: underline;
        font-size: medium;
<script type="text/javascript" src="jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(function () {
    $("#fileupload").change(function () {
        var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.jpg|.jpeg|.gif|.png|.bmp)$/;
        if (regex.test($(this).val().toLowerCase())) {
            if ($.browser.msie && parseFloat(jQuery.browser.version) <= 9.0) {
                $("#dvPreview")[0].filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = $(this).val();
            else {
                if (typeof (FileReader) != "undefined") {
                    $("#dvPreview").append("<img />");
                    var reader = new FileReader();
                    reader.onload = function (e) {
                        $("#dvPreview img").attr("src",;
                } else {
                    alert("This browser does not support FileReader.");
        } else {
            alert("Please upload a valid image file.");
    Browse Picture to view thw live image<br />
    <br />
<input id="fileupload" type="file" />
<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b>
    <span class="auto-style1"><em>Preview</em></span>
<br />
<br />
<div id="dvPreview">


Post a Comment

Copyright © DotNet-Ashok