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