0

I am trying to get the full path of the image but do not know how to do this? This is my jquery code::

$(document).ready(function () {
    $('#i_image').change(function () {
        var file = this.files;

        if (file && file[0]) {
            ReadImage(file[0]);
        }
    });

    var ReadImage = 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;
                
                
                $('#i_targetImg').attr('src', _file.target.result);
                
                $('#i_imagePrvw').show();
                // trying to get full path of the selected image...
                var fullPath = $('#i_targetImg').attr('src');
                $('#i_full_path').text(fullPath);
                
            }
        }
    };
});

var clearPreview = function () {
    $('#i_image').val('');
    $('#description').text('');
    $('#i_imagePrvw').hide();
};

front end code::

<div id="i_imagePrvw" class="thumbnail" style="display:none">
                                    <img class="img-responsive" id="i_targetImg" style="display:block; object-fit:fill;height:140px;width:120px;" />
                                    <div class="caption">
                                        <a href="#" onclick="clearPreview()"><i class="glyphicon glyphicon-trash"></i></a>
                                        
                                        <p id="i_full_path"></p>
                                    </div>
                                </div>
user4221591
  • 2,034
  • 6
  • 28
  • 60
  • For security reasons, browsers do not have acccess to the File System. Check this post here. https://stackoverflow.com/questions/15201071/how-to-get-full-path-of-selected-file-on-change-of-input-type-file-using-jav – Elie Asmar Nov 06 '21 at 08:44

0 Answers0