26

Possible Duplicate:
Dynamically set value of a file input

I have an input file HTML form and I want to set the initial value for the file path in an HTML form . I try to change tag "value" but it doesn't work anyway. <input type="file" name="testcase" value= "C:\test.txt">

Please give me some advice for this small problem. Thanks.

Community
  • 1
  • 1
aladine
  • 963
  • 3
  • 12
  • 35
  • 4
    It's not possible: http://stackoverflow.com/questions/1017224/dynamically-set-value-of-a-file-input – deceze Apr 19 '10 at 03:33
  • I did a full referenced and up-to date (dec 2013) answer about this here: [Remember and Repopulate File Input](http://stackoverflow.com/a/20537822/588079) – GitaarLAB Dec 16 '13 at 03:27
  • The "answer trail" created for this question by various moderators led me astray. The "Possible Duplicate" for this question, "Dynamically set value of a file input," while related, isn't the same question. *That* question is in turn marked as a duplicate of "How to set file input value when dropping file on page?" which certainly is a different question than this one. I agree: reopen. Since I can't answer this question because it's closed, and I'm out of characters in this comment, I'm leaving my answer as my next comment. – CODE-REaD Dec 15 '17 at 17:19
  • *Comment used as answer because the question is closed so I can't answer it:* Generally you can't set an initial value to `` for security reasons as explained below. But you can set a "filter" to control which files are shown in the user's selection window via the `accept` option to ``. See https://stackoverflow.com/questions/4328947/limit-file-format-when-using-input-type-file for details. – CODE-REaD Dec 15 '17 at 17:22

1 Answers1

39

From HTMLHelp.com :

The file input type creates a field through which users can upload files from their local computer or network. The VALUE attribute specifies the name of the initial file, but it is typically ignored by browsers as a security precaution.

Therefore, setting an initial value is not supported.

anonymous
  • 3,474
  • 25
  • 29
  • 1
    I tried to assign a value to a file input field via the firebug console and I've got a security exception.. So yeah, It can't be done – The Disintegrator Apr 19 '10 at 03:54