46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
||
|
||
namespace app\controller;
|
||
|
||
use think\Request;
|
||
use think\Env;
|
||
|
||
class Index
|
||
{
|
||
public function index(Request $request)
|
||
{
|
||
return json([
|
||
'code' => 200,
|
||
'msg' => 'success',
|
||
'data' => [
|
||
'name' => 'thinkphp6'
|
||
]
|
||
]);
|
||
}
|
||
|
||
public function upload()
|
||
{
|
||
$file = request()->file('file');
|
||
$trueName = $file->getOriginalName();
|
||
|
||
$env = new Env();
|
||
// thinkphp里面无法获取SERVER_ADDR变量,会被nacos拦截替换
|
||
$serverIP = $env->get('SERVICE_ADDR', '192.168.1.161:8000');
|
||
|
||
// 组装保存路径
|
||
$savename = \think\facade\Filesystem::disk('upload')->putFile('uploads', $file);
|
||
$savename = str_replace('\\', '/', $savename);
|
||
|
||
return json([
|
||
'code' => 200,
|
||
'msg' => null,
|
||
'data' => [
|
||
"name" => $trueName,
|
||
"url" => 'http://' . $serverIP . '/' . $savename,
|
||
// "url" => 'http://192.168.1.105:8080/file/' . $savename,
|
||
],
|
||
'env' => $env->get(),
|
||
]);
|
||
}
|
||
}
|