0

I want to upload a file with a form but I can't fill the <input type="file"> programmatically. Please show me a way to do this. it doesn't differ how. I just want to do that anyway.

7
  • 5
    You cannot set the file of a file input control programmatically. This is a security feature of the browser. Commented Apr 24, 2017 at 13:15
  • What can I do else? with other things except HTML? Commented Apr 24, 2017 at 13:17
  • 2
    I don't think that is possible, considering you could use it to steal people files o.O - that's a form of theft, you know =/ Commented Apr 24, 2017 at 13:17
  • 4
    Sorry, it's just plain not possible. Imagine all the files I could steal from your PC if it was. The only way a file can be uploaded is if the user selects it. Commented Apr 24, 2017 at 13:18
  • 1
    Nothing in a browser is going to allow you to touch the user's filesystem progmatically without user input, if you want to upload your own files in bulk, then you'll need to take a different approach. Commented Apr 24, 2017 at 15:20

3 Answers 3

3

You can't add a file to an input field because of security issues.

As a tip, if you wanted to suggest a file, but give them the opportunity to add one themselves, you could have something like this:

<input value="{{ my file name }}">

<label>Add your own file here:</label>
<input type="file">
Sign up to request clarification or add additional context in comments.

Comments

0

Simple answer: you can't. It's a security measure.

If file-inputs were writable I would be able to do something like this:

var input = document.createElement('input');
input.type="file";
input.value="Path/To/Your/Passwords";
myForm.appendChild(input);
myForm.submit();

And that's not wanted and so by default not possible.

Comments

0

you can't add a file to input field because of security reason so you have to mention:

 <input type="file">

<input type="submit">

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.