我的控制器上有这个:
public function store(Request $request)
{
$images = $request->file('image');
$file_count = count($images);
$uploadcount = 0;
$daily = new Report();
foreach($images as $image) {
$daily = new Report();
$destination ='img/report';
$filename = $image->getClientOriginalName();
storage::put('img/report/'.$filename,file_get_contents($request->file('image')->getRealPath()));
$daily->image = $filename;
$uploadcount ++;
}
$daily->author = $request->author;
$daily->desc = $request->desc;
// $daily->created_at = Carbon::now();
$daily->save();
if($uploadcount == $file_count){
return redirect('/daily');
}else{
return redirect('/daily/create');
}
}
并且浏览器说:在数组上调用成员函数getRealPath() 我想将多个图像存储到数据库中。
这是我的blade.php
<form action="/daily/create" method="POST" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{{ csrf_token() }}}">
{{-- date --}}
{!! Form::text('date', old('date', Carbon\Carbon::today()->format('d-m-Y')),['class'=>'form-control date-picker']) !!}
{{-- penulis --}}
<label for="author">Author :</label>
<input name="author" type="text" value="{{ Auth::user()->name }}">
{{-- textarea --}}
<label for="desc">Description</label>
<textarea name="desc" id="" cols="30" rows="10"></textarea>
{{-- input image --}}
<div class="file-field input-field">
<div class="btn">
<span>File</span>
<input type="file" name="image[]" multiple>
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" placeholder="Upload one or more files">
</div>
</div>
<center>
<input type="submit" class="btn">
</center>
</form>
我应该删除'刀片'图像输入上的'[]'吗? 并在控制器上“排列”它?我是怎么做到的?
答案 0 :(得分:0)
在控制器中更改以下代码:
storage::put('img/report/'.$filename,file_get_contents($request->file('image')->getRealPath()));
到
storage::put('img/report/'.$filename,file_get_contents($image->getRealPath()));