html5文件输入可以记住以前选择的文件吗? [英] Can a html5 file input remember the previous selected files?

查看:38
本文介绍了html5文件输入可以记住以前选择的文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个AJAX Multi-Upload,它将在表单/文件输入中获取所有选定的文件,并将其通过我的AJAX PHP控制器上传.在此过程中,我使用jQuery(1.11.3)和jQuery-Form插件.

I'm trying to create an AJAX Multi-Upload which will get all selected files within a form/file-input and upload this through my AJAX PHP Controller. For this process I'm using jQuery (1.11.3) and the jQuery-Form plugin.

除了一个非常烦人的问题外,一切都可以正常工作;当用户使用文件输入选择了几个文件,然后继续选择另外两个文件时,先前选择的文件将从"files []"数组中删除.以下是我的HTML5文件输入:

Everything works properly except a really annoying issue; When a user selects a couple of files with the file input and then proceeds to select another couple of files, the previous selected files are removed from the "files[]" Array. Following is my HTML5 file input:

<input id="multi-upload" type="file" name="files[]" multiple>

我的问题基本上是,是否可以仅追加新选择的文件,而不是覆盖旧的"files []".

My question is basically wether it is possible to just append the newly selected files, instead of overwriting the old "files[]".

我试图通过在JavaScript中创建一个数组来解决这种情况,该数组将在文件输入更改时将新文件推送到数组中,但这只会导致在发送文件时收到"blob"错误不幸的是,直接通过AJAX直接运行并不是很好.

I've tried to solve this situation by creating an Array in my JavaScript, which will push the new files in the array on change of the file input, but this will just result into receiving a 'blob' error as sending files directly through AJAX doesn't really work too well, unfortunatly.

因此,我知道唯一可行的选择是通过发送表单数据并与Controller一起获取$ _FILES参数,这使我回到了上述问题.

So the only option that I know of that could work is by sending the form data and grabbing the $_FILES parameter withing my Controller and this brings me back to the problem described above.

我想一种方法是根据文件输入的更改立即上传文件,但是由于人们应该能够编辑其文件名并能够取消文件的上传,因此这远非理想.

I guess a way would be to immediatly upload the files on change of the file input, but as people should be able to edit names of their files and be able to cancel the file from being uploaded, this is far from ideal.

所以我的问题是; 是否可以让新文件附加到文件输入中,而不是完全覆盖文件输入?还是有另一种方法可以实现这种目标?

很抱歉,如果某个地方隐藏着类似的问题,但我自己找不到任何已经正确回答的答案.

I'm sorry if there is a similar question hidden somewhere, but I haven't been able to find any answer myself that has been properly answered.

推荐答案

正如我在我的评论中提到的,您每次用户选择文件时都可以创建一个新输入...

As i mentioned in my comment you could just create a new input every time a user selects a file...

jQuery示例:

$(document).on('change','input[type="file"][multiple]',function(){
   var $this = $(this);
   $this.clone().insertAfter($this);
   $this.hide();
});

您当然不必使用jQuery,但这只是解释我的意思的最简单方法.

You don't have to use jQuery of course, but its just the simplest way to explain what i mean.

这篇关于html5文件输入可以记住以前选择的文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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