I'm following the answer HERE to create a file upload with image preview.
I have it working, but can't figure out how to place the file path in a separate div. Here's the 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 is the element where I want to place the file path text:
<div data-label="UploadPath"></div>
I have tried setting .text
on the reader.onload
function as such
$('[data-label="UploadPath"]').text(e.target.result);
But the result appears to be the base64 value of the image. Can you help me figure out how to include the path of the image in the data-label="UploadPath"
div? Thanks for your ideas! BTW, I'm new to jQuery so an example of how to include in my current code would help a lot. Thanks!