config/filesystems.php下更改
'disks' => [
'local' => [
'driver' => 'local',
// 'root' => storage_path('app'),
'root' => public_path(),
],
页面表单提交
<form action="{{Route('upload')}}" method="post" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label for="file">本地路径:</label>
<input type="file" name="img" id="file">
</div>
<button type="submit">添加</button>
</form>
路由
Route::post('upload', 'PhotoController@upload')->name('upload');
控制器
public function upload(Request $request)
{
$path = $request->file('img')->store('imge');
$data['title']=$request['title'];
$data['is_show']=$request['is_show'];
$data['img']=$path;
DB::table('photo')->insert($data);
}
|