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]);
}
}
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?
Share Improve this question edited Dec 13, 2018 at 10:16 Kunal Mukherjee 5,8533 gold badges28 silver badges55 bronze badges asked Dec 13, 2018 at 9:52 Black LeatherBlack Leather 731 gold badge3 silver badges11 bronze badges 4- 1 Nope! This is not possible! – kator Commented Dec 13, 2018 at 10:01
- @16kb okay.Thank you for ur response. – Black Leather Commented Dec 13, 2018 at 10:05
- 1 That is not possible! – Kunal Mukherjee Commented Dec 13, 2018 at 10:09
- Possible duplicate of How to get the filename from the Javascript FileReader? – Liam Commented Oct 1, 2019 at 12:57
3 Answers
Reset to default 9Is 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.
Add this in element:
onchange="loadFile(event)
var loadFile = function(event) {
var image = document.getElementById('output');
image.src = URL.createObjectURL(event.target.files[0]);
};
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);
}
}