设为首页 加入收藏

TOP

laravel文件上传
2019-08-24 00:02:49 】 浏览:35
Tags: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";
          }

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Laravel 系列入门教程(四)【最.. 下一篇navicate 远程无法链接linux上mys..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目