Search code examples
fileinputfontsopenfiledialog

get path from <input type="file"/>


I am using

    <input type="file" id="uploadFont" value="Upload Font"/>

to upload a font to my application. The open file dialog opens up and I choose the font.

How can I get the path of the choosen font.


Solution

  • This is browser-dependant, but on modern secure browsers you can't - and this is a good thing. If you were able to read this path, an attacker would also be able to, which is a huge information leak - for example it mostly gives him your username, if you chose a file from e.g. "My Documents" or your home directory.

    If you describe, what you need this path for, we might be able to help you conceive a workaround, but from the POV of your browser, this is just "some file", without the notion of its location in the underlying OS file tree.