[英]How to show upload box from Dropzone.js if no image is found | Laravel 5.2
I have a problem with my Profile upload. 我的个人资料上传有问题。 I am using laravel 5.2, and Im using the Dropzone.js plugin to upload user profile photos. 我正在使用laravel 5.2,而我正在使用Dropzone.js插件上传用户个人资料照片。 My problem is when I upload a profile photo i set it to maxFilesize 1. So it only uploads 1 photo at a time. 我的问题是当我上传个人资料照片时,将其设置为maxFilesize1。因此,一次只能上传1张照片。 BUT, when the upload is done, a user can go back and upload one more photo, so then the user will have 2 photos for their profile picture. 但是,上传完成后,用户可以返回并再上传一张照片,因此该用户的个人资料照片将有2张照片。
I need to make it so if a user already has a Profile Photo, so the dropzone upload box doesnt show up, until that profile photo is deleted or there is not any photos. 如果用户已经有个人资料照片,则我需要这样做,以便在删除该个人资料照片或没有任何照片之前,不会显示dropzone上传框。 Here is what the Dropzone Upload box looks like: 这是Dropzone Upload框的外观:
Here is my Dropezone.js script: 这是我的Dropezone.js脚本:
<script>
Dropzone.options.addPhotosForm = {
paramName: 'photo',
maxFilesize: 2,
acceptedFiles: '.jpg, .jpeg, .png, .bmp',
maxFiles: 1,
// Refresh page when upload is complete.
init: function () {
this.on("queuecomplete", function (file) {
if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
location.reload();
}
});
}
}
</script>
Here is how the photo is shown: 这是照片的显示方式:
@foreach ($user->photos as $photo)
<form method="post" action="{{ route('profile.destroy', ['id' => $photo->id]) }}" enctype="multipart/form-data">
{!! csrf_field() !!}
<input type="hidden" name="_method" value="DELETE">
<button type="submit" class="close">×</button>
<img class="ui small circular image" src="/travels/{{ $photo->thumbnail_path }}" alt="" data-id="{{ $photo->id }}">
</form>
@endforeach
And here is my file upload form: 这是我的文件上传表格:
<form
action="/travels/{{ $user->username }}/photos"
method="post"
class="dropzone"
id="addPhotosForm"
enctype="multipart/form-data">
{{ csrf_field() }}
</form>
This is the outcome with 2 or more profile photos which I DONT WANT 这是2张或以上我不想要的个人资料照片的结果
I figured it out with 3 jQuery lines 我用3条jQuery行弄清楚了
if($('#image').length){
$('#FormUpload').hide();
}
I added #image to the actual image if there is one and added #Formupload to the actual form upload box, and just checked if the image appears on the page then hide the upload box 我将#image添加到实际的图像(如果有的话),并将#Formupload添加到实际的表单上载框,然后仅检查图像是否显示在页面上,然后隐藏上载框
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.