ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
上传的配置文件`/config/filesystems.php`,上传的目录可配置也可不配置, 上传的目录的可在保存文件的同时写上 ``` 'disks' => [ 'local' => [ 'driver' => 'local', 'root' => storage_path('app'), ], 'public' => [ 'driver' => 'local', 'root' => storage_path('app/public'), 'url' => env('APP_URL').'/storage', 'visibility' => 'public', ], //这是新增的保存目录 'uploads' => [ 'driver' => 'local', 'root' => storage_path('app/uploads'), 'url' => env('APP_URL').'/storage', //'visibility' => 'uploads', ], 's3' => [ 'driver' => 's3', 'key' => env('AWS_ACCESS_KEY_ID'), 'secret' => env('AWS_SECRET_ACCESS_KEY'), 'region' => env('AWS_DEFAULT_REGION'), 'bucket' => env('AWS_BUCKET'), ], ], ``` ***** 1.html文件 ``` <form class="form-horizontal" method="POST" action="" enctype="multipart/form-data"> {{ csrf_field() }} <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}"> <label for="password" class="col-md-4 control-label">请选择文件</label> <div class="col-md-6"> <input id="file" type="file" class="form-control" name="source" required> @if ($errors->has('password')) <span class="help-block"> <strong>{{ $errors->first('password') }}</strong> </span> @endif </div> </div> <div class="form-group"> <div class="col-md-8 col-md-offset-4"> <button type="submit" class="btn btn-primary"> 确认上传 </button> </div> </div> </form> ``` ***** 2.php代码 ``` if($request->isMethod('post')){ $file = $request->file('source'); if($file->isValid()){ //原文件名 $originalName = $file->getClientOriginalName(); //扩展名 $ext = $file->getClientOriginalExtension(); //MimeType $type = $file->getClientMimeType(); //临时绝对路径 $realPath = $file->getRealPath(); //第一种存储方式 //文件名laravel自动生成 //$path = $file->store('uploads'); //自行生成文件名 //$path = $file->storeAs('uploads','55544.'.$ext); //第二种存储方式 $fileName=date('Y-m-d-H-i-s').'-'.uniqid().'.'.$ext; $path = Storage::putFile('uploads', $file); //$bool=Storage::disk('uploads')->put($fileName,file_get_contents($realPath)); //var_dump($bool); var_dump($path); } //dd($file); //exit(); } ```