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

Alon Gubkin picture Alon Gubkin · Nov 8, 2009 · Viewed 656.8k times · Source

How can I set the value of this?

<input type="file" />

Answer

BalusC picture BalusC · Nov 8, 2009

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? =)