From eb7916922630948486e314da5ab5a41c67ee50bb Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Thu, 16 Nov 2023 16:19:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=9B=BE=E7=89=87=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/adminapi/controller/UploadController.php | 22 ++++++++++++++++++++ app/common.php | 19 +++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/app/adminapi/controller/UploadController.php b/app/adminapi/controller/UploadController.php index cb1999bb..536d6c86 100644 --- a/app/adminapi/controller/UploadController.php +++ b/app/adminapi/controller/UploadController.php @@ -43,6 +43,28 @@ class UploadController extends BaseAdminController } } + //上传图片 + public function taskImage(): Json + { + $params=$this->request->post(); + $result = curl_post_file(env('project.worker_domain').'/middleapi/upload/image', $_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'],$this->reqHeader); + if($result['code'] == 0){ + return $this->fail($result['msg']); + } + return json($result); + } + + //上传文件 + public function taskFile(): Json + { + $params=$this->request->post(); + $result = curl_post_file(env('project.worker_domain').'/middleapi/upload/file', $_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'],$this->reqHeader); + if($result['code'] == 0){ + return $this->fail($result['msg']); + } + return json($result); + } + /** * @notes 上传视频 * @return Json diff --git a/app/common.php b/app/common.php index 50a59ba9..d70e48e0 100644 --- a/app/common.php +++ b/app/common.php @@ -345,6 +345,25 @@ function curl_post($url,$data,$headers=[]) { curl_close($ch); return json_decode($output,true); } + +function curl_post_file($url, $filePath, $fieldName, $fieldExt, $headers=[]) { + //初始化curl + $ch = curl_init($url); + $cfile = curl_file_create($filePath, $fieldExt, $fieldName); + // 设置 POST 数据 + $data = array('file' => $cfile); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_POST,1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); + + $output = curl_exec($ch); + curl_close($ch); + return json_decode($output,true); +} function curl_get($url){ $ch = curl_init();