javascript - Image Upload Preview File Path -
i'm following answer here create file upload image preview.
i have working, can't figure out how place file path in separate div. here's js:
function readurl(input) { if (input.files && input.files[0]) { var reader = new filereader(); reader.onload = function (e) { $('[data-label="uploadpreview"]').children('img').attr('src', e.target.result); } reader.readasdataurl(input.files[0]); } } $('#uploadinput').change(function(){ readurl(this); });
this element want place file path text:
<div data-label="uploadpath"></div>
i have tried setting .text
on reader.onload
function such
$('[data-label="uploadpath"]').text(e.target.result);
but result appears base64 value of image. can me figure out how include path of image in data-label="uploadpath"
div? ideas! btw, i'm new jquery example of how include in current code lot. thanks!
the way have written you're trying target img
tag child of data-label=uploadpath
, if put in empty <img/>
script can append image so:
you can append <img/>
tag instead of leaving blank 1 in there, choice
update:
just grab value when uploading, can use regex strip out path before filename if needed
update again stripped out path file name:
Comments
Post a Comment