php laravel 阿里云对象存储 多图上传 前端手机端页面遍历输出

10 篇文章 0 订阅
1 篇文章 0 订阅

上传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对象存储图片上传

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值