0

我能够将值写入输入 t 表单类型 = 文本

例如

 <input type="text" value="xyz">

但我想要的是,将一个值写入 input type="file" 。我已经尝试了下面的代码,但它不起作用。

 <input type="file" value="something">
4

2 回答 2

7

出于相当明显的安全原因,您不能。

如果网页可以为文件输入指定默认值,那么它可以(例如)指定c:\place\where\finance\software\stores\accounts\by\default(然后使用 JavaScript 提交表单,而无需用户执行任何操作)。

于 2012-10-15T08:20:59.373 回答
0

PHP aside, HTML doesn't let you assign values to input type="file" elements as a security measure. If HTML had this power, you could setup several of these fields and point each one to a windows file on the user's computer. The result would be a victim submitting a form with no idea they were also submitting sensitive information. No JavaScript is required. The victim might submit such a form to log in or post a comment on a blog somewhere. Why wouldn't the victim notice they are also submitting a file? CSS can style such elements offscreen using negative coordinates so its a lot like an input type="hidden", just in this case it would submitting a file instead.

于 2012-10-15T08:28:04.153 回答