使用dropzone而不自动上传 [英] use dropzone without auto uploading

查看:86
本文介绍了使用dropzone而不自动上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用drop zone拖放多个文件up-loader。它所做的是使用Ajax自动将文件上传到服务器。但是我希望它能够执行另一个功能。我希望每当我选择一个文件时,它应该创建一个< input type =filename =file1>< input type =filename =file2> 等等。
所以,最后我点击提交按钮。然后我应该能够手动上传。

I want to use drop zone drag and drop multiple file up-loader. the thing it does is automatically uploads file to server using Ajax. But I want it to perform another function. I want that whenever I select a file it should create a <input type="file" name="file1"><input type="file" name="file2"> and so on with every field holding that file. so , when at the end i click on submit button. then I should be able to upload it manually.

情况是我要上传产品。通过拖放我将上传产品的图片。我知道这张图片可以上传,价值可以保存到数据库,但是,在我还没有提交表格的时候,还没有产品ID。并且在图像选项卡中有字段,我们在其中输入产品ID。任何建议来实现这一点。

The scenario is that i am going to upload products. by drag and drop i will be uploading pictures of the products. I know this picture can be uploaded and values can be saved to database but, for the time i have not submitted the form there is no product id yet. and there is field in images tab where we enter the product id. any suggestion to achieve this.

推荐答案

你应该将autoProcessQueue参数设置为false。

You should set autoProcessQueue parameter to false.

你可以这样做:

HTML - 添加按钮

<form action="your_action" class="dropzone" id="your_form_id">
     <div class="fallback">
         <input name="file" type="file" />
     </div>
</form>

<button type="button" id="btn_upload">Upload</button>

JavaScript - 将autoProcessQueue设置为false,在按钮ID上添加click事件并触发processQueue上传文件的事件

Dropzone.options.your_form_id = {
    autoProcessQueue: false,

    init: function (e) {

        var myDropzone = this;

        $('#btn_upload').on("click", function() {
            myDropzone.processQueue(); // Tell Dropzone to process all queued files.
        });

        // Event to send your custom data to your server
        myDropzone.on("sending", function(file, xhr, data) {

            // First param is the variable name used server side
            // Second param is the value, you can add what you what
            // Here I added an input value
            data.append("your_variable", $('#your_input').val());
        });

    }
};

这篇关于使用dropzone而不自动上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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