2017-01-16 22 views
0

私はdropzone.jsで初めて複数のファイルをアップロードする作業を行っています....しかし、いくつかの問題があります.... 基本的に私が達成しようとしているのは、会議IDに対して複数のファイルをアップロードすることです。私はmeeting_idという名前の入力フィールドがあり、プログラムでdropezoneを作成しています。 は、以下の私はMEETING_IDがMEETING_IDとしてinput_textと名前の値であるdropezone.jsのURLオプションを動的に変更する方法

  url:'upload.php?meeting_id='+meeting_id+''; 

ようdropezoneのURLを変更したいです何をしたい今、私のjavascriptのコード

 Dropzone.autoDiscover = false; 
     jQuery(document).ready(function() { 
     var arr=JSON.parse('<?echo $json_ext_arr?>').toString(); 
     var myDropzone = new Dropzone("#myId", { 
     url:'upload.php', 
     autoProcessQueue:false, 
     maxFiles:5, 
     acceptedFiles: arr 
     }); 

     }); 

      var meeting_id=$('#meeting_id).val() 

ある

答えて

1

私はあなたの質問を正しく理解していれば、これがあなたの後であると信じています:

Dropzone.autoDiscover = false; 
    jQuery(document).ready(function() { 
       var arr = JSON.parse('<?echo $json_ext_arr?>').toString(); 
       var myDropzone = new Dropzone("#myId", { 
        url: 'upload.php?meeting_id=' + $("#meeting_id").val(), 
        autoProcessQueue: false, 
        maxFiles: 5, 
        acceptedFiles: arr 
       }); 
あなたが行うことができます

または次の場合、ドロップダウンリストのオプションの変更を動的URLを更新しようとしているとき

myDropzone.options.url = 'upload.php?meeting_id=' + $("#meeting_id").val() 
1

私もこの問題に直面していました。しかし、DOMの準備が整った後に変更されたときは機能しません。

以下のようなオプションを変更するたびに、Dropzoneを動的にロードすることでこの問題を解決できました。

ステップ1:のようにHTMLでのdivコンテナを定義し、以下の

<div id="dzContainer"> 
<!-- Drag and Drop control is dynamically placed here to upload files to databse --> 
</div> 

ステップ2:ドロップゾーンコントロールとdivの記入上

function ReloadDropZone(optionName) { 

      //Create <div class="dropzone" id="dropzoneForm"> 
      var iDiv = document.createElement('div'); 
      iDiv.id = 'dropzoneForm'; 
      iDiv.className = 'dropzone'; 
      document.getElementById('dzContainer').appendChild(iDiv); 

      // Create <div id="innerDiv" class="fallback"> 
      var innerDiv = document.createElement('div'); 
      innerDiv.id = 'innerDiv'; 
      innerDiv.className = 'fallback'; 
      document.getElementById('dropzoneForm').appendChild(innerDiv); 

      /// Create <input name="file" type="file" multiple/> 
      var iInput = document.createElement('input'); 
      iInput.name = 'file'; 
      iInput.type = 'file'; 
      iInput.id = 'inputFile'; 
      document.getElementById('innerDiv').appendChild(iInput); 
      document.getElementById('inputFile').setAttribute('multiple','multiple'); 

      ///<input type="submit" value="Upload" /> 
      var iSubmit = document.createElement('input'); 
      iSubmit.value = 'Upload'; 
      iSubmit.type = 'submit'; 
      document.getElementById('innerDiv').appendChild(iSubmit); 

      // Dropzone class: 
      $("div#dropzoneForm").dropzone({ 
       url: 'apiurl' + optionName, 
       dictDefaultMessage: "", 
       autoDiscover: false, 
       maxFiles: 2000, 
       maxFilesize: 0.2, 
       acceptedFiles: ".jpeg,.jpg,.png", 
       complete: function (file){}, 
       error: function (file, response) {}, 
       init: function() {} 
      }); 
} 
関連する問題