使用文件输入选择多个文件时删除单个文件 [英] Remove Individual Files When Multiple FIles Are Selected With File Input

查看:120
本文介绍了使用文件输入选择多个文件时删除单个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

允许用户选择多个文件时,是否可以从要上载的文件列表中删除单个文件?例如,我有一个看起来有点像这样的输入:

 < input type ='file'name ='file' id ='file'multiple ='multiple'/> 

用户选择4张照片,1.jpg,2.jpg,3.jpg和4。 JPG。是否有可能删除4.jpg,因为用户改变主意并且不想上传那个? 解决方案

简短的回答就是'不'。 不可能更改文件的值从脚本输入元素:否则它将是一个庞然大物的安全洞大小。让我向你保证:在处理文件输入时,一些浏览器(IE,这就是你!)变得非常挑剔。但是你可以使用以下方法:让用户上传尽可能多的文件和你想要的(尽管设置一些限制是明智的),但是把它们放到临时存储器中。只有当用户真正表达他们希望保存附加这些文件的实体时,才会将这些文件转换为永久状态。



或者可能是考虑使用一些回退机制,Flash或类似的东西。实际上,还有另一个原因:IE8不支持文件选择器中的多个属性。


Is it possible to remove individual files from the list of files to be uploaded when the user is allowed to select multiple files? For example, I have an input that looks somewhat like that:

<input type = 'file' name = 'file' id = 'file' multiple = 'multiple' />

And the user selects 4 photos, 1.jpg, 2.jpg, 3.jpg and 4.jpg. Is it possible to remove 4.jpg, because the user changed their mind and doesn't want to upload that one?

解决方案

The short answer would be just 'No'. It's not possible to change the value of file input element from a script: it would be a security hole size of a mammoth otherwise. And let me assure you: some browsers (IE, that's about you!) become VERY picky when dealing with file inputs.

But you can use the following approach: let users upload as many files as you and they want (it's prudent to set some limits, though), but put them into some temporary storage. Only when users actually express their desire to save the entity to which these files are attached, move these files into a permanent state.

Or may be it's time to think about using some fallback mechanisms, Flash or something like that. In fact, there's another reason to do it: IE8 doesn't support multiple attribute on the file picker.

这篇关于使用文件输入选择多个文件时删除单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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