上传html
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">活动相关:</label>
<div class="col-sm-4">
<input type="file" name="introduce[]" class="form-control" id="inputEmail3" placeholder="活动图片"><br/>
<input type="file" name="introduce[]" class="form-control" id="inputEmail3" placeholder="活动图片"><br/>
<input type="file" name="introduce[]" class="form-control" id="inputEmail3" placeholder="活动图片"><br/>
<input type="file" name="introduce[]" class="form-control" id="inputEmail3" placeholder="活动图片"><br/>
<input type="file" name="introduce[]" class="form-control" id="inputEmail3" placeholder="活动图片"><br/>
<input type="file" name="introduce[]" class="form-control" id="inputEmail3" placeholder="活动图片"><br/>
<input type="file" name="introduce[]" class="form-control" id="inputEmail3" placeholder="活动图片"><br/>
<input type="file" name="introduce[]" class="form-control" id="inputEmail3" placeholder="活动图片"><br/>
</div>
</div>
上传控制器
//多图上传
if($request->hasFile('introduce')) {
//dd($_FILES['introduce']);die;
foreach($request->file('introduce') as $key => $file) {
//$file->move(base_path().'/public/uploads/', $file->getClientOriginalName());
$fileName =md5($file->getClientOriginalName().time().rand()).".".$file->getClientOriginalExtension();
$bool = Storage::put('uploads/admin/'.$fileName,file_get_contents($file->getRealPath()));
$data['introduce'][$key] = $fileName."&&";
}
}
$data['introduce'] = implode("", $data['introduce']);//注意这里是因为数组无法写进数据库
前端展示控制器
//加载活动详情页面
public function show2($id)
{
// dd('ok');
$act = \DB::table('act')->where('id',$id)->first();
$act2 = [];
$act2 = json_decode(json_encode($act),true); ///dd($act2['introduce']);
$act2['introduce'] = explode("&&", $act2['introduce']);
//dd($act2);
return view('h5.act.act',compact('act2'));
}
//注意这里有一个对象转数组 然后从数据库拿出来是字符串需要转成数据
前端页面输出
<div class="jieshao" style="width:100%">
<div class="jieshao1" style="width:100%">
@foreach($act2['introduce'] as $key=>$value)
<img style="display:block;width:100%;" src="http://hrtvoss.oss-cn-beijing.aliyuncs.com/uploads/admin/{{$act2['introduce'][$key]}}">
@endforeach
</div>
</div>
点击查看 阿里云oss对象存储图片上传