子钦加油

扩大
缩小

laravel文件上传

        $file = Request::file('photo');//文件
        $name = input::get('name');//其他属性值
        $allowed_extensions = ["png", "jpg", "gif"];
        if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
            return ['error' => 'You may only upload png, jpg or gif.'];
        }
        $destinationPath = 'storage/uploads/'; //public 文件夹下面建 storage/uploads 文件夹
        $extension = $file->getClientOriginalExtension();
        $fileName = str_random(10).'.'.$extension;
        $file->move($destinationPath, $fileName);
        $filePath = asset($destinationPath.$fileName);
        $info=DB::insert('insert into photo(pname,photo) VALUES (?,?)',[$name,$filePath]);//入库
          if($info){
           return Redirect('/show');
          }else{
              echo "no";
          }

 

posted on 2019-01-10 16:12  子钦加油  阅读(432)  评论(0编辑  收藏  举报

导航

返回顶部