我尝试使用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.但问题是没有上传图像并且没有保存数据。那么如何检查我的代码中哪个部分有错误?或者我该如何解决这个问题?