From 2bd157debb9e89cb72a8656208147e7e766a0cbd Mon Sep 17 00:00:00 2001 From: woon Date: Wed, 12 Apr 2023 11:29:11 +0800 Subject: [PATCH] update --- public/index.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/public/index.php b/public/index.php index 87072fe..70b7d65 100644 --- a/public/index.php +++ b/public/index.php @@ -244,14 +244,32 @@ function api_test() function api_upload() { + $url = "https://telegra.ph/upload"; + + $filePath = $_FILES["file"]["tmp_path"]; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, array( + 'file' => new CURLFile($filePath) + )); + $response = curl_exec($ch); + curl_close($ch); + + $jsonArr = json_decode($response, true); + + $src = $jsonArr[0]["src"] ?? ""; + echo_json([ - "code" => 0, - "msg" => "success", + "code" => empty($src) ? 1 : 0, + "msg" => "", "data" => [ "id" => $_POST["id"], - "src" => 123 + "src" => $src ] ]); + + } // api func end