Javascript&文件上传字段 - 操作文件输入 [英] Javascript & File Upload Fields - Manipulating File Input

查看:110
本文介绍了Javascript&文件上传字段 - 操作文件输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

上传控件的多个文件选择


我可以使用

 < input name =userfile []type =filetitle = 选择您的文件multiple =/> 

让用户一次选择多于1个文件。但是将所有文件分离成个别文件输入通过javascript?



作为一个例子,我点击选择我的输入文件,并选择Image1.jpg,image2.jpg。和image3.jpg,同时按住ctrl进行多重选择。然后,一旦我点击一个按钮,就会触发一个功能,将该输入分割成每个文件的多个单个文件输入。

解决方案

出于安全考虑,这是不可能的。由于@Pointy声明(在对该问题的评论中),您不能这样做,因为浏览器的安全模型不会让您通过JavaScript操纵该字段的值。



这个问题有许多解决方案(例如 SWFUpload ),它们允许您使用Flash控件来允许用户选择尽可能多的文件(他们甚至允许您过滤什么文件类型(和/或大小))允许...但他们将自动拆分文件到可以正常或异步通过AJAX上传的单独的字段。 / p>

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.

解决方案

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.

这篇关于Javascript&amp;文件上传字段 - 操作文件输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆