配置上传地址 filesystem.php
<?php
return [
'default' => env('filesystem.driver', 'local'),
'disks' => [
'local' => [
'type' => 'local',
'root' => app()->getRootPath() . 'public/storage',
],
'public' => [
'type' => 'local',
'root' => app()->getRootPath() . 'public/storage',
'url' => '/storage',
'visibility' => 'public',
],
],
];
具体代码
<?php
namespace app\controller;
use think\facade\Filesystem;
use think\facade\Request;
class Upload
{
public function upload()
{
$file = Request::file('image');
$info = Filesystem::putFile('topic',$file,'md5');
$filePath = Filesystem::getDiskConfig('public', 'url') . '/' . $info;
return json(['status' => 'success', 'file_path' => $filePath]);
}
}
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="http://tp6.com/upload/upload" enctype="multipart/form-data" method="post">
<input type="file" name="image">
<input type="submit" value="确定">
</form>
</body>
</html>

