Search code examples
javascripthtmlfile-uploadpreset

How to set a value to a file input in HTML to a client side disk file system path?


How can I set the value of this?

<input type="file" />

Solution

  • You cannot set it to a client side disk file system path, due to security reasons.

    Imagine:

    <form name="foo" method="post" enctype="multipart/form-data">
        <input type="file" value="c:/passwords.txt">
    </form>
    <script>document.foo.submit();</script>
    

    You don't want the websites you visit to be able to do this, do you? =)

    You can only set it to a publicly accessible web resource as seen in this answer, but this is clearly not the same as a client side disk file system path and it's therefore useless in that context.