: 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.php
는
http://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 + '~';
}
}
}
위에게 :
이렇게했습니다. 감사 :) – NoReceipt4Panda