How can I set the value of this?
<input type="file" />
The only way to set the value of a file input is by the user to select a file. This is done for security reasons. Otherwise you would be able to create a JavaScript that automatically uploads a specific file from the client's computer.
A file input's value attribute contains a string that represents the path to the selected file(s). If no file is selected yet, the value is an empty string ( "" ). When the user selected multiple files, the value represents the first file in the list of files they selected.
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? =)
You can't.
The only way to set the value of a file input is by the user to select a file.
This is done for security reasons. Otherwise you would be able to create a JavaScript that automatically uploads a specific file from the client's computer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With