Let's say I have a HTML file named site.html
. The full path name of this file is C:\Users\Anton\Documents\Projects\site.html
.
This html file is a simple program to open and show images.
I use <input type='file'>
, so that the user may select the image he wants to view:
<input type='file></input>
-> user selects an image, information about the image is displayed at the top of the page, e.g.:
name: marker.png type: image/png size: 20921 Bytes
I access these information with fileInput.files[0].name
, fileInput.files[0].type
.. and so on.
Until here it works perfectly fine.
But then it comes to displaying the image.
To do this I used <object width="400" height="400" id='obj' data=""></object>
I added some JavaScript:
function showPic() {
...
document.getElementById('obj').data = fileInput.files[0].name;
}
fileInput.oninput = showPic;
Then it actually had to work, but the image just didn't display.
Chrome and some other Browsers threw a net::ERR_FILE_NOT_FOUND
.
After I tried to open the image via Ctrl + Mouse-Click
in the browser console I realised that the file of the image input has to be in the same path the actual HTML file is. Otherwise, the image is searched in C:\Users\Anton\Documents\Projects
and if the file isn't there, net::ERR_FILE_NOT_FOUND
is thrown.
My question: How can I show a file that's not in the same path as the HTML file? I would need the full image path to solve that, but apparently, security browsers like Chrome or MS Edge don't allow that. So is there another way to fix this problem? Thanks in advance.