创建配置文件在 data/config/filesystem.php
return [
'default' => 'local',
'disks' => [
'local' => [
'type' => 'local',
'root' => app()->getRuntimePath() . 'storage',
],
'public' => [
'type' => 'local',
'root' => app()->getRootPath() . 'public/storage',
'url' => '/storage',
],
],
];
该处 在创建public磁盘:在更目录的public目录下创建storage文件夹用于存储
前端HTML
<form method="post" action="{:url('portal/gz/post_info_post')}" enctype="multipart/form-data">
控制器中
use think\facade\Request;
use think\facade\Filesystem;
$file = request()->file('path');
if (!$file) {
return json(['code' => 0, 'msg' => '未上传文件']);
}
#判断是否上传
$savename = Filesystem::disk('public')->putFile('gz', $file);
#其中返回的信息 $savename
#"gz/20250725/c4219efc6dd44ef8e439b85ed03d667c.png"
#即public下的 storage下