Html 将删除的文件附加到 <input type="file" multiple>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15194365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Appending Dropped File to <input type="file" multiple>
提问by Bren1818
I'm not sure if this is possible or not, I'm writing my own file upload plugin with jQuery which is working great, but what I would like to do is enhance user experience by allowing the user to drop a file from their desktop into a div and having that file append to my input
我不确定这是否可行,我正在用 jQuery 编写自己的文件上传插件,效果很好,但我想做的是通过允许用户从桌面删除文件来增强用户体验放入 div 并将该文件附加到我的输入
I have the drag and drop working, same with upload, but currently the drag and drop, is separate from the uploading of multiple.
我有拖放工作,与上传相同,但目前拖放与多个上传是分开的。
So in my html5 drop function I'd like to do something like this:
所以在我的 html5 drop 函数中,我想做这样的事情:
<div id="dropZone"></div>
<!--Drop area is seperate from the fileUpload below-->
<form enctype="multipart/form-data">
<input class="clear" name="nonImagefilesToUpload[]" id="nonImagefilesToUpload" type="file" multiple/>
</form>
this.drop = function(e){
e.stopPropagation();
e.preventDefault();
files = e.dataTransfer.files ;
for (var i = 0, file; file = files[i]; i++) {
//pseudo code
if ( !file.type.match(settings.imageTypeMatch )) {
//not an image so I want to append it to my files array
$('#nonImagefilesToUpload').append( file[i] );
//hoping this will also trigger my input change
}else{
var reader = new FileReader();
reader.onload = (function(aFile) {
return function(evt) {
if (evt.target.readyState == FileReader.DONE)
{
//code to handle my images
//which are uploaded seperate via xhr
}
})(file);//done reading the file
//read the file
reader.readAsDataURL(file);
}
}
return false;
};
If anyone could help with this it'd be appreciated, it may not be possible due to securities, but I thought I'd ask
如果有人可以帮助解决这个问题,我们将不胜感激,由于证券的原因,这可能是不可能的,但我想我会问
采纳答案by Samuel Liew
You are correct. You cannot change the value of a file
input field.
你是对的。您不能更改file
输入字段的值。
Edit:
编辑:
From 2017, you can set dropped files into a file input. See How to set file input value when dropping file on page?
从 2017 年开始,您可以将删除的文件设置为文件输入。请参阅如何在页面上放置文件时设置文件输入值?