Dropzone acceptedFiles错误

时间:2015-05-07 05:49:27

标签: dropzone.js

请帮助过滤要上传的图片类型,我已经做了一些试验和错误,但无法让它工作。这是我的代码:

$(document).ready(function(){ 

   Dropzone.autoDiscover = false;
   var myDropzone = new Dropzone("#mydropzone",{
      url:"upload.php",
      uploadMultiple: true,
      maxFilesize: 2,
      maxFiles : 3,
      acceptedFiles: ".jpg,.jpeg,.png", <-- this won't work
      dictInvalidFileType: "You can't upload files of this type, only png or jpg file",
      autoProcessQueue : true,
      parallelUploads: 3,
      addRemoveLinks: true,
   });
});

我试过了:

acceptedFiles: "image/jpg,image/jpeg,image/png",

但目录中仍然没有上传..如果我删除了逗号:

acceptedFiles: ".jpg,.jpeg,.png"

它工作,上传显示在我的目录文件夹,但它接受所有类型的上传..是否有某种订单使这项工作?有人帮忙吗?

3 个答案:

答案 0 :(得分:2)

您可以使用init函数

        var myDropzone = new Dropzone("#designdocumentexcel",
            {
                acceptedFiles : ".xls,.xlsx,.csv",
                init: function(){
                    this.on("error", function(file, errorMessage) {
                        alert("error : " + errorMessage );
                    });

                },
            }
        );

答案 1 :(得分:1)

试一试:

$(function(){
    // Dropzone.autoDiscover = false; <-- You don't need it, remove it!
    Dropzone.options.mydropzone = { <!-- string mydropzone is the form id
        url:"upload.php", <-- Put this in form action
        acceptedFiles: "image/jpeg,image/png", <-- jpeg = jpeg/jpg
        // the other options...
    };
});

希望有所帮助:)

答案 2 :(得分:0)

您必须插入“ /path/to/dropzone.js” 而不是CDN

,然后在该文件中,您可以将config acceptFiles:null更改为..like

acceptedFiles:“图像/ *”,