跟小D每日学口语

TP6 实现上传文件

//接受前台传来的file文件
        $file = Request::file('file_upload');
        //验证文件规则
        $result=validate(['file' => ['fileSize:102400,fileExt:gif,jpg,png']])->check(['file' => $file]);
        if($result){
            //上传到服务器,
            $path = Filesystem::disk('public')->putFile('upload',$file);
            //结果是 $path = upload/20200825\***.jpg
            
            //图片路径,Filesystem::getDiskConfig('public','url')功能是获取public目录下的storage,
            $picCover = Filesystem::getDiskConfig('public','url').'/'.str_replace('\\','/',$path);
            //结果是 $picCover = storage/upload/20200825/***.jpg
            
            //获取图片名称
            $fileName = $file->getOriginalName();
        }

 

posted @ 2020-09-13 17:00  明仔¥  阅读(1266)  评论(0编辑  收藏  举报