【发布时间】:2018-02-24 17:18:12
【问题描述】:
我正在使用 laravel 和 dropzone.js
当我一张一张上传图片时,效果很好。
但是,当我选择多张图片(例如 3 张图片)时。
它确实保存了图像 3 次,但它保存了最后一张选择的图像,而不是 1、2 和 3。它是 3、3 和 3。
这很奇怪,因为它实际上做了 3 个请求,因此每个图像都应该单独保存。
这是我的表格:
<div class="z-index">
<button id="modal-open" data-toggle="modal" data-target="#myModalHorizontal">Upload Gallery</button>
</div>
<div class="col-xs-12">
<div class="modal fade" id="myModalHorizontal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" onclick="refreshPage();">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<h4 class="modal-title" id="myModalLabel">
Drag & Drop images or click to upload
</h4>
</div>
<div class="modal-body">
<form style="height: 50vh;" action="{{ url('/uploadgallery')}}" class="dropzone" id="gallery">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
</div>
</div>
</div>
</div>
</div>
和控制器:
public function gallery(ImgRequest $request)
{
if ($request->hasFile('file')) {
$s3Path = config('app.path', public_path());
$file = Input::file('file');
print_r($file);
$filePath = 'public/gallery/' . time() . '.' . $file->getClientOriginalExtension();
$path = $s3Path . $filePath;
Storage::disk('s3')->put($filePath, file_get_contents($file), 'public');
$session = session()->get('key');
$image = new Images;
$image->path = $path;
$image->entity_id = $session;
$image->save();
print_r($path);
}
【问题讨论】:
标签: laravel laravel-5 dropzone.js