如何伪造ajax文件上传?

时间:2022-02-20 03:48:52

I've an upload form I would like to populate with a file, in particular an image.

我有一个上传表单,我想填充一个文件,特别是一个图像。

My understanding is that I need to create a File object to put in the FileList of the relative form. Currently the image I have is in the data URI format "data:image/png;base64,..." but I can change that.

我的理解是我需要创建一个File对象来放入相对表单的FileList。目前我的图像是数据URI格式“data:image / png; base64,...”但我可以改变它。

If that is true how do I create the correct File object from an image and add it to the FileList? If it is not do you suggest a better solution?

如果确实如此,如何从图像创建正确的File对象并将其添加到FileList?如果不是,你建议一个更好的解决方案?

1 个解决方案

#1


4  

Use a regular form and target it to an iframe with display set as none.

使用常规表单并将其定位到iframe,并将显示设置为none。

<form id="my_form" enctype="multipart/form-data" action="upload_handler.php" method="POST" target="upload_target">
   <input name="uploadfile" type="file" />
   <input type="submit" value="Upload File" />
</form>
<iframe id="upload_target" name="upload_target" style="display:none;"></iframe> 

#1


4  

Use a regular form and target it to an iframe with display set as none.

使用常规表单并将其定位到iframe,并将显示设置为none。

<form id="my_form" enctype="multipart/form-data" action="upload_handler.php" method="POST" target="upload_target">
   <input name="uploadfile" type="file" />
   <input type="submit" value="Upload File" />
</form>
<iframe id="upload_target" name="upload_target" style="display:none;"></iframe>