We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Wednesday, September 5, 2018

How to Upload Pic and display in a div and display the size, height, width and also delete in jquery



        <div class="col-md-9">

    <div class="col-md-4">
        <div class="btn btn-primary">
            <input type="file" id="fileImage" />
        </div>
        <div id="imagePreview" class="thumbnail" style="display:none">
            <img class="img-responsive" id="targetImg" />
            <div class="caption">
                <a href="#" id="btbClear"><i class="glyphicon glyphicon-trash"></i></a>
                <p id="description"> </p>
            </div>

        </div>
    </div>

</div>
<script src="~/Scripts/jquery-1.10.2.js"></script>

<script>
    $(document).ready(function () {
        $("#fileImage").change(function () {

            var file = this.files;
            if (file && file[0]) {
                PreImage(file[0]);
            }
        });


        var PreImage = function (file) {

            var reader = new FileReader;
            var image = new Image;

            reader.readAsDataURL(file);
            reader.onload = function (_file) {
                image.src = _file.target.result;
                image.onload = function () {
                    var height = this.height;
                    var width = this.width;
                    var type = file.type;
                    var size = ~~(file.size / 1024) + "KB";
                    $("#targetImg").attr('src', _file.target.result);
                    $("#description").text("Size" + size + "," + height + "x" + width + "," + type + ",");
                    $("#imagePreview").show();
                }
            }
        }


        $("#btbClear").click(function () {

            $("#fileImage").val('');
            $("#description").text();
            $("#imagePreview").hide();

        });
    });
</script>


No comments: