php laravel 阿里云对象存储 多图上传 前端手机端页面遍历输出
2017-10-26 17:07
363 查看
上传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对象存储图片上传
<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对象存储图片上传
相关文章推荐
- Laravel中上传视频至阿里云对象存储OSS中
- Laravel整合UEditor编辑器使用阿里云OSS存储(二)改造UEditor上传OSS
- Java使用阿里云OSS对象存储上传图片
- 上传文件到阿里云OSS对象存储,查询访问地址,删除文件
- Laravel5.2之PHP对象遍历(Iterator)
- php文件分类上传以及前端遍历显示
- thinkPHP实现对象存储oss,将图片上传到阿里云oss
- Spring+SpringMVC+Mybatis整合百度富文本编辑器Ueditor,上传图片到阿里云OSS对象存储。
- C# .net Ueditor实现图片上传到阿里云OSS 对象存储
- thinkPHP实现对象存储oss,将图片上传到阿里云oss
- 阿里云OSS ueditor 直接上传oss对象存储遇到的问题
- Laravel5.2 集成阿里云--OSS对象存储服务
- Java使用阿里云OSS对象存储上传图片
- 上传阿里云oss对象型存储 本地文件和上传流上传
- Laravel整合UEditor编辑器使用阿里云OSS存储(二)改造UEditor上传OSS
- 阿里云对象存储OSS配置介绍设置,上传代码示例
- 阿里云oss对象存储图片上传
- 阿里云对象存储OSS--实现随时随地上传文件到阿里云
- Java使用阿里云OSS对象存储上传图片
- PHP简易文件上传系统 For 阿里云存储 v1.3