简体   繁体   English

使用jQuery从上传队列中删除文件

[英]Remove file from upload queue using jQuery

I have written my own uploader for a site I'm working on. 我已经为正在处理的网站编写了自己的上传器。 It's got drag and drop and all those nice features. 它具有拖放功能以及所有这些不错的功能。 One thing it does, is check your files against values on a database. 它做的一件事是对照数据库中的值检查文件。 Should a file not match a value, it get's "thrown out" and placed in an Unknown file box. 如果文件不匹配值,则将其“抛出”并放置在“未知文件”框中。

I want to, when the user clicks upload, remove these files from the upload form, thus not uploading them at all. 我想当用户单击“上传”时,从上传表单中删除这些文件,从而根本不上传它们。 At the moment it uploads them, but doesn't do anything with them, but I do not want this, as it wastes time . 目前,它会上传它们,但不对它们做任何事情, 但是我不希望这样做,因为这会浪费时间

Is this possible? 这可能吗?

Here's a little bit of code, just so I don't depress anyone. 这里有一些代码,只是为了让我不沮丧。

My form, generated by cakePHP: 我的表单,由cakePHP生成:

<?php echo $this->Form->create('Upload',array('type'=>'file')); ?>
    <fieldset>
        <legend><?php echo __('Upload Files'); ?></legend>
        <?php
            echo $this->Form->input('files.',array('type'=>'file','multiple','label'=>'Upload Files'));
        ?>
    </fieldset>
<?php echo $this->Form->end(); ?>

When the file upload changes, my jQuery is invoked and it sorts the files. 当文件上传发生变化时,我的jQuery被调用并对其进行排序。

My jQuery where the user clicks a button and it uploads looks like this: 用户单击按钮并上载的jQuery如下所示:

$('.submit-upload').on('click',function() {
    $('#UploadAddForm').submit();
});

Unfortunately you cant. 不幸的是你不能。 You can only delete the entire file upload list by setting its value to an empty string. 您只能通过将其值设置为空字符串来删除整个文件上传列表。

$("#filelist").val("");

Managing individual files however isn't possible. 但是无法管理单个文件。 Please see: http://www.w3.org/TR/FileAPI/#dfn-filelist 请参阅: http : //www.w3.org/TR/FileAPI/#dfn-filelist

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM