简体   繁体   中英

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:

<?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.

My jQuery where the user clicks a button and it uploads looks like this:

$('.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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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