0
我有以下代码:如何检查在dropzone中是否已有图像?
CODE JS:
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("div#myDrop", {
url : "<?php echo $this->serverUrl() . '/profile/ajax/dzupload'; ?>",
paramName : 'profilepicture',
acceptedFiles : "image/*",
maxFiles : 1,
addRemoveLinks : true,
init : function() {
this.on("success", function(file, responseText) {
$('#profilePicture').attr("value", responseText.filename);
console.log(responseText);
});
this.on("maxfilesexceeded", function(file){
this.removeFile(file);
alert("You are not allowed to chose more than 1 file!");
});
this.on("removedfile", function (file){
$.ajax({
method: 'POST',
url: '<?php echo $this->serverUrl() . '/profile/ajax/dzdelete' ?>',
data: {
area : 'company-profile',
name : $('#profilePicture').attr('value')
},
success: function(result){
$('#profilePicture').attr("value", '')
console.log(result);
}
})
});
}
});
var fileName = $('#profilePicture').val();
var mockFile = { name: fileName, size: 12345 };
myDropzone.options.addedfile.call(myDropzone, mockFile);
myDropzone.options.thumbnail.call(myDropzone, mockFile, "<?php echo $this->serverUrl().'/public/profile/'.'usr'.$practitionerInfo->user_id.'/picture/'.$practitionerInfo->profilepicture ?>");
我想检查是否有已加载图像......如果不是有那么让你添加其他图像,直到我删除以前的
我试着下面的代码,但它不工作
if(!myDropzone.file.length()){
//allow to upload file
}else{
alert("please remove existing file");
}
我该怎么做?我希望我能够解释得很好。
编辑:
如果添加此代码0,但画面增收默认,应该是一个,对不对?
console.log(myDropzone.files.length) //return 0
请看我编辑的帖子 –
@ D.Cristi'files'数组只包含Dropzone控件中的文件。如果您想阻止用户上传第二张个人资料照片,则可以在您的成功处理程序中禁用上传内容,或者使用新照片替换现有的个人资料照片。 – twernt