2

I want to fake a file uploading form, e.g

<form action=upload.php method=post enctype='multipart/form-data'>
   <input type=file name=userfile>
   <input type=submit>
</form>

Normally you will have to click on the userfile object and select a file.

Now, is it possible to fake the content of that input? I mean, I've encoded file contents in javascript, and I don't want user interaction, just use the pre-defined value when the browser try to read the "fake file"

Is that possible?

I already tried Cross Domain AJAX posting with HTML5, but that would require CORS enabled on server side.

daisy
  • 22,498
  • 29
  • 129
  • 265
  • Why is it all of a sudden cross domain? You won't be able to modify the input: http://stackoverflow.com/questions/5632629/how-to-change-the-file-inputs-filelist – Ian Mar 05 '14 at 15:24

2 Answers2

0

All file uploads must be user-initiated to prevent malware from sending unauthorized files. You many need to base-64 encode your file and send it via AJAX + POST.

See: Send a file with XmlHttpRequest: Streaming?

Community
  • 1
  • 1
Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
0

You cannot do that in javascript. Inputs with type="file" are read-only for security reasons.

I suggest you to encode your file to base64 and put content of it in hidden input.

rgtk
  • 3,240
  • 1
  • 30
  • 36