Javascript & File Upload Fields - Manipulating File Input [duplicate]

青春壹個敷衍的年華 提交于 2019-12-11 13:49:17

问题


Possible Duplicate:
Multiple file selection for an upload control

Is it possible for me to use a

<input name="userfile[]" type="file" title="Select Your Files" multiple=""/>

To have the users select more than 1 file at once.. But then Separate all the files into individual file inputs via javascript?

As an example, i click to choose files for my input, and select Image1.jpg, image2.jpg. and image3.jpg all while holding ctrl for the multi-selection.. Then once i click on a button, a function is triggered that'll split that input into multiple single file inputs for each file.


回答1:


This is not possible for security reasons. As @Pointy stated (in a comment to the question) you can't do this because the browsers' security model will not let you manipulate the value of the field with JavaScript.

There are many solutions to this problem (e.g. SWFUpload) that allow you to use a flash control to allow the user to pick as many files as desired (they even let you filter on what filetypes (and/or sizes)) are permitted... yet they will auto-split the files into separate fields that can be uploaded as normal or asynchronously via AJAX.



来源:https://stackoverflow.com/questions/6636064/javascript-file-upload-fields-manipulating-file-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!