Take the 2-minute tour ×

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>

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.

share|improve this question
Why is it all of a sudden cross domain? You won't be able to modify the input: stackoverflow.com/questions/5632629/… –  Ian Mar 5 at 15:24

2 Answers 2

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?

share|improve this answer

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.

share|improve this answer

Your Answer


