0

I am able to write value to an input t form type= text

for ex

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

But what i want is, to write a value to input type="file" . I have tried the code below but it's not working.

 <input type="file" value="something">
1
  • <input type="file" name="fileName" value="C:/hello world/test.txt" size=80> Commented Oct 15, 2012 at 8:22

2 Answers 2

7

You cannot, for fairly obvious security reasons.

If a webpage could specify a default value for a file input, then it could (for example) specify c:\place\where\finance\software\stores\accounts\by\default (and then use JavaScript to submit the form without the user having to do anything).

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.