How to set the value of an HTML file field?

Note:

The answers and comments below reflect the status of outdated browsers in 2009. Now you can really set the value of the file entry element dynamically / programmatically using JavaScript in 2017.

See the answer in this question for details, as well as a demo:
How to set file input value programmatically (for example: when dragging files)?

In HTML, we can set the value of a text field by writing:

<input type="text" name="doc_intitule" maxlength="100" size="24" value="<?php echo $ret['doc_intitule']; ?>"> 

But how to set the value of the file field?

+2
source share
3 answers

Please refer to this

How to save input type = file field value after failed validation in ASP.NET MVC?

As far as I know, you should not pre-set the values ​​of the file fields for security purposes.

+5
source

You cant set the value of the file field by any means. See Here: Information

+3
source

You cannot set a default value for a file field.

This is a security feature: you can simply submit the form by code so that you can force the user to upload the file without their knowledge.

+2
source

All Articles