2016-08-25 1 views
1

파일 업로드에 dropzone을 사용하고 있습니다. 한 번에 하나의 이미지를 업로드하는 경우 파일 제한을 최대 6 개까지 설정할 수 있지만이 이미지를 6 개 이상 선택하면이 코드가 작동합니다 파일 업로드 시작시 컨트롤 버튼을 누르면 파일의 유효성을 검사하지 않고 모든 파일을 업로드합니다. 내가 백엔드 laravel을 사용하고, 내 코드는 다음과 같습니다 -Dropzone이 최대 파일 수를 확인하지 않음

Dropzone.options.myAwesomeDropzone = { 
    paramName: "file", // The name that will be used to transfer the file 
    maxFilesize: 1, // MB 
    maxFiles: 6, 
    acceptedFiles: ".jpeg,.jpg,.png,.gif", 
    clickable: true, 
    init: function() { 
     this.on("success", function(file, responseText) { 
      file.previewTemplate.setAttribute('id',responseText[0].id); 
     }); 
     this.on("thumbnail", function(file) { 
      if (file.width < 350 || file.height < 200) { 
       file.rejectDimensions() 
      } 
      else { 
       file.acceptDimensions(); 
      } 
     }); 
    }, 
    accept: function(file, done) { 
     file.acceptDimensions = done; 
     file.rejectDimensions = function() { done("Image width or height should be greater than 350*200"); }; 
    }, 
    removedfile: function(file){ 
     var name = file.name; 
     $.ajax({ 
       type: 'POST', 
       url: ajax_url+'listing/deleteListingImage/'+name, 
       dataType: 'html' 
      }); 
      var _ref; 
      return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0; 
      }, 
      dictDefaultMessage: "Drop your files to upload" 
    } 

감사

+0

A.은'console'의 모든 오류? B. [docs about it] (http://www.dropzonejs.com/#config-maxFiles)을 읽으셨습니까? 그것은 유효하지 않습니다. 그냥 'maxfilesexceeded'이벤트를 호출하는 것입니다. –

+0

그것의 유효화 벌금 유일한 문제는 내가 6 개 이상의 이미지를 한 번에 업로드하는 경우입니다 –

+0

또한 콘솔에서 오류를주지 마십시오 –

답변

0

당신은 maxfilesexceeded가 호출되는 방법 removeFile(file)를 사용하여 별도의 파일을 제거 할 수 있습니다. 이처럼

:

Dropzone.options.myAwesomeDropzone = { 
 
    maxFiles: 2, 
 
    autoProcessQueue: false, 
 
    init: function(){ 
 
    var myDropZone = this; 
 
    myDropZone.on('maxfilesexceeded', function(file) { 
 
     myDropZone.removeFile(file); 
 
    }); 
 
    } 
 
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.3.0/dropzone.css"> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.3.0/min/dropzone.min.js"></script> 
 
<form action="/file-upload" 
 
     class="dropzone" 
 
     id="my-awesome-dropzone"> 
 

 
</form>

http://output.jsbin.com/dodajij

+0

autoProcessQueue : false를 설정하는 이유는 자동으로 파일을 업로드하지 않기 때문입니까? 왜냐하면이 코드를 추가 할 때 아무 일도 일어나지 않고 autoprocessQueue를 제거해도 여분의 파일을 제거하지 않고 모든 파일을 계속 업로드하기 때문입니다. –

+0

확실히 :'autoProcessQueue : false'는 요청 양식을 처리 할 서버가 없기 때문에 데모 용 일뿐입니다. 제거해야합니다. –

+0

어디서 오류가 발생했는지, 우리는 accept 함수를 사용하여 코드의 유효성을 검사 할 수 있습니다. 코드에서 언급 한 바와 같이 함수의 accept 함수를 제거하면 코드가 올바르게 작동합니다. 수락 기능의 대체품이 있습니까? –

관련 문제