1.如果要将上传的文件存在本地的pubilc/home/images文件中将config目录的filesystem.php修改成return [
// 默认磁盘
‘default’ => env(‘filesystem.driver’, ‘local’),
// 磁盘列表
‘disks’ => [
‘local’ => [
‘type’ => ‘local’,
‘root’ => app()->getRuntimePath() . ‘storage’,
],
‘public’ => [
// 磁盘类型
‘type’ => ‘local’,
// 磁盘路径
‘root’ => app()->getRootPath() . ‘public/static/home’,
// 磁盘路径对应的外部URL路径
‘url’ => ‘/images’,
// 可见性
‘visibility’ => ‘public’,
],
// 更多的磁盘配置信息
],
];就可以了。
图片验证问题:
$ files = request()->file();
try {
validate([‘image’=>‘fileSize:10240|fileExt:jpg,png,gif’])
->check($files);
foreach($files as $file) {
$savename= \think\facade\Filesystem::disk('public')->putFileAs( 'images', $file,$image);
}
} catch (\think\exception\ValidateException $e) {
alert($e->getMessage());
}
$image就是需要保存在image目录中的文件名。