thinkphp 接收文件并处理

html前台文件,上传到控制器,thinkphp处理它

 

 

前台

    <form action="{:url('product/brand_addcl')}" enctype="multipart/form-data" method="post" class="form form-horizontal" id="form-article-add">

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>缩略图:</label>
            <div class="formControls col-xs-8 col-sm-9">
            <input accept="image/*" type="file" name="image" />
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <button type="submit" onClick="article_save_submit();" class="btn btn-primary radius" type="submit"> 添加</button>
            </div>
        </div>
    </form>

 

 

后台

 

    //品牌添加处理
    public function brand_addcl(){
       
       $file = request()->file('image');
        if(!$file){
            $this->error('图片文件接收报错!');
        }

   
        //存储到本地,路径从public开始
        $info = $file->move("static/uploads/");
        if(!$info){
             $this->error('图片文件存储报错!');
        }
        $data['logo_img'] = $info->getSaveName();

        $res = Brand::create($data);
        if(!$res){
             $this->error('添加品牌失败!');
        }       
       echo "<script language=JavaScript>  alert('操作成功!');
  parent.location.reload();  
</script>";
    }

 

posted @ 2018-09-05 16:39  cl94  阅读(453)  评论(0编辑  收藏  举报