tp6 文件上传 验证是否有文件上传

$data=Request::post();
            $oldimg=public_path()."storage/".ProductModel::find($data['id'])->img;
            if(file_exists($oldimg)){
                unlink($oldimg);
            }
            try {
                // 获取表单上传文件
                $file = Request::file('img');
            } catch (\Exception $e) {
            }
            if(isset($file)){
                // 上传到本地服务器
                $data['img'] = \think\facade\Filesystem::disk('public')->putFile( '/upload', $file);
            }
            if(ProductModel::update($data)){
                return redirect('index');
            }else{
                return redirect('add');
            }

 

posted @ 2020-08-05 09:45  CanyingV  阅读(1027)  评论(0)    收藏  举报