第一步: config/filesystem.php 文件
return [
// 默认磁盘
'default' => env('filesystem.driver', 'public'),
// 这里上传的文件会上传到 public/uploads/ 下
// 磁盘列表
'disks' => [
'local' => [
'type' => 'local',
'root' => app()->getRuntimePath() . 'storage',
],
'public' => [
'type' => 'local',
'root' => app()->getRootPath() . 'public/uploads',
'url' => '/uploads',
'visibility' => 'public',
],
'images' => [
'type' => 'local',
'root' => app()->getRootPath() . 'public/uploads/images',
'url' => '/uploads/images',
'visibility' => 'public',
],
// 更多的磁盘配置信息
],
];
第二步:
public function fileUp()
{
$files = request()->file('image');
if (empty($files)) {
return to_json(0, '请选择上传文件', 1);
}
$savename = [];
if (is_array($files)) {
foreach($files as $file){
$savename[] = \think\facade\Filesystem::putFile('topic', $file);
}
} else {
$savename[] = \think\facade\Filesystem::putFile('topic', $files);
}
var_dump($savename);
exit();
}
|