You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.5 KiB
87 lines
2.5 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\api\controller\upload;
|
|
|
|
use app\service\api\upload\Base64Service;
|
|
use app\service\api\upload\FetchService;
|
|
use app\service\api\upload\UploadService;
|
|
use core\base\BaseApiController;
|
|
use think\Response;
|
|
|
|
class Upload extends BaseApiController
|
|
{
|
|
|
|
/**
|
|
* 图片上传
|
|
* @return Response
|
|
*/
|
|
public function image(){
|
|
$data = $this->request->params([
|
|
['file', 'file'],
|
|
]);
|
|
$upload_service = new UploadService();
|
|
$file_path = $upload_service->image($data['file']);
|
|
|
|
|
|
$ol_url = get_file_url($file_path['url']);//文件相对路径转绝对路径
|
|
|
|
// 获取文件名称和后缀名
|
|
$file_name = basename($ol_url);
|
|
$file_ext = pathinfo($ol_url, PATHINFO_EXTENSION);
|
|
|
|
// 组装 $res 数组
|
|
$res = [
|
|
'path' => $file_path['url'], // 文件上传后的相对路径
|
|
'url' => $ol_url, // 文件绝对路径
|
|
'name' => $file_name, // 文件名称
|
|
'ext' => $file_ext // 文件后缀名
|
|
];
|
|
return success($res);
|
|
}
|
|
|
|
/**
|
|
* 视频上传
|
|
* @return Response
|
|
*/
|
|
public function video(){
|
|
$data = $this->request->params([
|
|
['file', 'file'],
|
|
]);
|
|
$upload_service = new UploadService();
|
|
return success($upload_service->video($data['file']));
|
|
}
|
|
|
|
/**
|
|
* 远程图片拉取
|
|
* @return Response
|
|
*/
|
|
public function imageFetch(){
|
|
$data = $this->request->params([
|
|
['url', ''],
|
|
]);
|
|
$fetch_service = new FetchService();
|
|
return success($fetch_service->image($data['url']));
|
|
}
|
|
|
|
|
|
/**
|
|
* base64图片上传
|
|
* @return Response
|
|
*/
|
|
public function imageBase64(){
|
|
$data = $this->request->params([
|
|
['content', ''],
|
|
]);
|
|
$base64_service = new Base64Service();
|
|
return success($base64_service->image($data['content']));
|
|
}
|
|
}
|
|
|