我尝试使用 Laravel 上传。这是我的添加图像模式:
<div id="imagesModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"></h4>
</div>
<div class="modal-body">
<form name="imagesForm" id="addImages" class="form-horizontal dropzone" role="form" method="POST" action="{{ route('images.add') }}" enctype="multipart/form-data">
{{ csrf_field() }}
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
这是我的 jquery 和 dropzone 设置:
$( "#addImages" ).click(function(event) {
event.preventDefault();
save_method = 'add';
$('#imagesModal').modal("show");
$('.modal-title').text('Add Images')
});
Dropzone.options.addImages = {
paramName: "images", // The name that will be used to transfer the file
maxFilesize: 2, // MB
/*params: {
'id' : $('#addImages').attr('data-gallery-id')
}*/
};
在 images.add 的控制器中,我有这样的功能:
public function store(Request $request)
{
foreach ($request->file as $file) {
$image = new Image();
$image->gallery_id = 7;
$image->name = $file->getClientOriginalName();
$image->extension = $file->extension();
$image->size = $file->getClientSize();
$image->save();
// Or any custom name as the third argument
Storage::putFileAs('public'.'/'.'test'. '/', $file, $file->getClientOriginalName());
return response($file->getClientOriginalName(). 'uploaded succesfully');
}
}
它在我的控制台中上传没有任何错误,作为响应它给出 200。但问题是没有上传图像并且没有保存数据。那么我如何检查我的代码的哪一部分有错误?或者我该如何解决这个问题?