dsv38843 2016-06-10 10:40
浏览 114

Dropzone无法上传文件并将其移动到文件夹中

Hi I'm new to jquery and dropzone library, I unable to upload files using dropzone. I wanted to do multiple file upload using dropzone whenever I drag and drop multiple image or doc inside dropzone and click submit, I have edit and change all my code and it still not working.. I unable to move or upload the files into the folder. Any help and suggestion please. I use here as reference https://github.com/enyo/dropzone/wiki/Combine-normal-form-with-Dropzone.

Javascript

var unique = 'ufiles';
Dropzone.options.myAwesomeDropzone = {
    url: "../../scripts/submission-upload.php",
    autoProcessQueue: false,
    autoDiscover: false,
    uploadMultiple: true,
    parallelUploads: 100,
    paramName: unique,
    previewsContainer: ".dropzone-previews",
    maxFilesize: 50, //MB
    maxFiles: 100,
    acceptedFiles: "image/*, application/pdf, .doc, .docx",
    addRemoveLinks: true,
    dictRemoveFile: 'Remove',
    dictFileTooBig: 'File is bigger than 50MB',
    accept: function(file, done) {
        console.log("uploaded");
        done();
    },
    error: function(file, msg){
        alert(msg);
    },
    init: function () {
        var myDropzone = this;

        // First change the button to actually tell Dropzone to process the queue.

        $('input[type=submit]').on("click", function(e){
            e.preventDefault();
            e.stopPropagation();
            myDropzone.processQueue();
            //$("#upload-forms").submit();
        });
        // Listen to the sendingmultiple event. In this case, it's the sendingmultiple event instead
        // of the sending event because uploadMultiple is set to true.
        this.on("sendingmultiple", function() {
            // Gets triggered when the form is actually being sent.
            // Hide the success button or the complete form.
            $("#upload-forms").submit();
        });
        this.on("successmultiple", function(files, response) {
            // Gets triggered when the files have successfully been sent.
            // Redirect user or notify of success.
        });
        this.on("errormultiple", function(files, response) {
            // Gets triggered when there was an error sending the files.
            // Maybe show form again, and notify user of error
        });
    }
}

Upload PHP

$uploaddir = '../submissions/';
$uploadfile = $uploaddir.$_FILES['ufiles']['name'];
foreach ($FILE['ufiles']['tmp_name'] as $file) {
  echo $file;
  if (move_uploaded_file($_FILES['ufiles']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.
";
  } else {
    echo "Error!
";
  }
}

HTML

<form method="post" action="scripts/submission-upload.php" id="upload-forms" enctype="multipart/form-data">
  <div class="dropzone dropzone-previews" id="my-awesome-dropzone">
    <div class="fallback">
      <input name="file[]" type="file" multiple>
    </div>
  </div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
  • 写回答

2条回答 默认 最新

  • douyo770657 2016-06-11 10:34
    关注

    The submit button inside form tag trigger two events i.e, its default form submission and your function. You need to perform you function before default form submission. Instead of doing this

    $('#submit').submit(function(){
         dropzone.processQueue();
    });
    

    Do this

    <form onsubmit="return someFunction();" ...>
    

    And write a function like this

    function someFunction(){
        dropzone.processQueue();
        return false;
    }
    

    I found a similar solution here also Javascript shortcuts for loops, conditions and return functions

    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R