How to set a value to a file input in HTML?

How can I set the value of this?

<input type="file" />

Answer

You cannot, 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? =)

Leave a Reply

Your email address will not be published. Required fields are marked *