2017-03-24 4 views
0
내가가 제공 Dropzone.js 자원의 해제거야

: http://www.dropzonejs.com/ 내가을 할 노력하고있어 무엇Dropzone JS : 프로세스를 업로드 한 후 각 이미지의 URL을 별도의 AJAX 요청으로 전달하는 방법은 무엇입니까?

- 이미지 (들)을 업로드하고 모든 입력을 작성 후, 각 이미지에 대한 링크를 얻을 수 이 세션에서 업로드 된 URL은 POST 유형으로 AJAX 요청 URL로 전달됩니다.

내 HTML :

<div id="myForm"> 
    <input type="text" id="form-name" placeholder="Name"> 
    <input type="text" id="form-email" placeholder="Email"> 

    <form action="/upload-target" class="dropzone" id="myDropZone"></form> 

    <button id="submit-info">submit</button> 
</div> 

내 JS :

<script> 
    $("div#myDropzone").dropzone({ url: "/upload.php" }, 
     function() { 
      console.log("Hello"); 
     }); 
</script> 

이미지는 아래의 PHP 코드에서 언급 한 디렉토리에 업로드됩니다,하지만 난 위의 스크립트는에 문제가 콘솔의 출력물이 출력되지 않습니다. 아무 것도 업로드되면 Hello이 콘솔에 표시되지 않습니다. 내 upload.php

:

<?php 
    $ds   = DIRECTORY_SEPARATOR; 

    $storeFolder = 'img/uploads'; 

    if (!empty($_FILES)) { 

     $tempFile = $_FILES['file']['tmp_name'];   

     $targetPath = dirname(__FILE__) . $ds. $storeFolder . $ds; 

     $targetFile = $targetPath. $_FILES['file']['name']; 

     move_uploaded_file($tempFile,$targetFile); 

    } 
?> 

그냥 위의 코드를 한 번 이미지 (들)을 설명하는 선택/드래그 - 앤 - dorpped 입니다 upload.phphttp://example.com/img/uploads/ 폴더에 이미지를 업로드합니다. 내가 도움을 필요로하는 곳에 여기

는 다음과 같습니다

내가 바로 AJAX 요청에 문자열로 업로드 한 각 이미지를 전달 아이디 submit-info와 버튼을 클릭 할 때를 위해 노력하고 있습니다 :

<script> 
    $('#submit-info').click(function() { 
     var str = "name=" + $('#form-name').val() 
       + "&email=" + $('#form-email').val() 
       + "&images=" + /* what to put here */; 

     console.log(str); 

     $.ajax({ 
      type: "post", 
      url: "sendEmail.php", 
      data: str, 
      dataType: "json", 
      success: function (confirmation) { 
       // some code here dealing with after the email is sent like hiding the form 
      } 
     }); 
    }); 
</script> 

var files = ''; 

if (Dropzone.forElement("#my-dropzone").files.length > 0) { 
    for (var i = 0; i<Dropzone.forElement("#my-dropzone").files.length; i++) { 
     if (i === (Dropzone.forElement("#my-dropzone").files.length - 1)) { 
      files += Dropzone.forElement("#my-dropzone").files[i].name; 
     } 
     else { 
      files += Dropzone.forElement("#my-dropzone").files[i].name + '~'; 
     } 
    } 
} 

위에게 :

답변

0

여기 그것을하는 하나의 방법입니다 코드는 $('#submit-info').click(function() { ... 안에 있어야하며 제출 버튼을 클릭하면 빈 문자열을 설정하고 업로드 된 파일이 있는지 확인한 다음 파일이 있으면 연결합니다.

이 예제의 경우 파일은 ~ 자로 구분됩니다. 문자열이 전달되면 str 변수를 다음과 같이 선언 할 수 있습니다.

+0

이렇게했습니다. 감사 :) – NoReceipt4Panda