【发布时间】:2016-03-04 14:28:12
【问题描述】:
我有以下代码:
代码 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但是图片加了receive default应该是1吧?
console.log(myDropzone.files.length) //return 0
【问题讨论】:
标签: javascript jquery html dropzone.js