laravel中文件上传:
laravel5.5版本:
congfig下的filesystems.php中配置:uploads信息:
'uploads' => [ 'driver' => 'local', 'root' => storage_path('app/uploads') ],
文件存储地址:storage/app/uploads
上传文件表单必须定义:enctype="multipart/form-data"
<form enctype="multipart/form-data"></form>
控制器:
public function file(Request $request){ $file=$request->file('source'); //文件是否上传成功: if ($file->istValid()){ //原文件名: $originalName=$file->getClientOriginalName(); //扩展名: $ext=$file->getClientOriginalExtension(); //MimeType: $type=$file->getClientMimeType(); //临时绝对路径: $realPath=$file->getRealPath(); $filename=date('Y-m-d-H-i-s').'-'.uniqid().'.'.$ext; $bool=Storage::dish('uploads')->put($filename,file_get_contents($realPath)); var_dump($bool); } }