欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

laravel文件上传

程序员文章站 2022-04-05 10:10:17
$file = Request::file('photo');//文件 $name = input::get('name');//其他属性值 $allowed_extensions = ["png", "jpg", "gif"]; if ($file->getClientOriginalExtens... ......
        $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";
          }