Reputation: 73
Hi i have these codes to read the file the user has uploaded:
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#myImg').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
And the output is a whole chunk of data:
Is there any way i can get the path from the data? for example C:\Users\blackLeather\Desktop
If no,is there another way to get the image directory without having to add into another folder?
Upvotes: 6
Views: 13257
Reputation: 174
Like stated before you can't get the URL where the file lived, but you can create one.
function createFileURL() {
var uploadedFile = document.getElementById("customFile").files[0];
var reader = new FileReader();
reader.readAsDataURL(uploadedFile);
reader.onload = function () {
return URL.createObjectURL(uploadedFile);
}
}
Upvotes: 1
Reputation: 29
Add this in element:
onchange="loadFile(event)
var loadFile = function(event) {
var image = document.getElementById('output');
image.src = URL.createObjectURL(event.target.files[0]);
};
Upvotes: 1
Reputation: 1075159
Is there any way i can get the path from the data?
No. None at all. That information is not provided to the JavaScript layer by the browser, for security reasons.
Upvotes: 9