1、為了訪問方便,將上傳的檔案保存在 public 目錄下,需要進行修改配置,
找到 config/filesystems.php 檔案然后修改 root、具體如下:
'local' => [
'driver' => 'local',
// 'root' => storage_path('app'),
'root' => public_path()
],
'public' => [
'driver' => 'local',
// 'root' => storage_path('app/public'),
'root' => public_path(),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
2、配置路由,指定上傳頁面;
// 上傳頁面
Route::get('/upl', function(){
return view('Users.upload');
});
3、創建并編輯上傳頁面;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>上傳</title>
</head>
<body>
<form action="uplDo" method="post" enctype="multipart/form-data">
<!-- 檔案上傳使用 post 提交方式、需要加 csrf 保護-->
@csrf
檔案上傳:
<input type="file" name="file" id="">
<input type="submit" value=https://www.cnblogs.com/laowenBlog/p/"提交">
