1.选择图片&上传
2.图片链接
名称 大小 状态 链接

this is about

404 NOT FOUND
1, "msg" => "uri错误", "data" => [] ]); call_user_func($func); } } function echo_json($data) { header('Content-Type: application/json; charset=utf-8'); echo json_encode($data, JSON_UNESCAPED_UNICODE); die; } function api_test() { echo_json([ "code" => 0, "msg" => "test", "data" => [] ]); } function api_upload() { $web = "https://demo.winxg.com"; $url = "https://telegra.ph/upload"; $filePath = $_FILES["file"]["tmp_name"]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 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"] ?? ""; $uuid = uniqidReal(); exec_db("INSERT INTO files (uuid, src) VALUES ('{$uuid}', '{$src}')"); echo_json([ "code" => empty($src) ? 1 : 0, "msg" => "", "data" => [ "id" => $_POST["id"], "src" => $web . "/file/{$uuid}" ] ]); } // api func end ?> prepare("SELECT * FROM files WHERE uuid=:uuid LIMIT 1"); $stmt->bindParam(':uuid', $id); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); if (empty($row['src'])) { echo_json([ "code" => 1, "msg" => "图片不存在", "data" => [] ]); } $imgUrl = "https://telegra.ph{$row['src']}"; $content = file_get_contents($imgUrl); header('Content-Type: image/jpeg'); header('Content-Length: ' . strlen($content)); echo $content; die; } } function get_page_title() { $uri = $_SERVER['REQUEST_URI']; $pages = json_decode(file_get_contents(CONFIG_PATH . "page.json"), true); return $pages[$uri]["title"] ?? "404 NOT FOUND"; } function show_page() { $uri = $_SERVER["REQUEST_URI"]; $func = ltrim(implode("_", explode("/", $uri)), "_"); if (function_exists("show_{$func}")) { call_user_func("show_{$func}"); } else { call_user_func("show_404"); } } function get_db() { $db = new PDO('sqlite:' . DATA_PATH . 'data.db'); return $db; } function exec_db($sql) { $db = get_db(); $db->exec($sql); } function inti_db() { exec_db('CREATE TABLE IF NOT EXISTS files (id INTEGER PRIMARY KEY, uuid TEXT, src TEXT)'); } function uniqidReal($lenght = 13) { // uniqid gives 13 chars, but you could adjust it to your needs. if (function_exists("random_bytes")) { $bytes = random_bytes(ceil($lenght / 2)); } elseif (function_exists("openssl_random_pseudo_bytes")) { $bytes = openssl_random_pseudo_bytes(ceil($lenght / 2)); } else { throw new Exception("no cryptographically secure random function available"); } return substr(bin2hex($bytes), 0, $lenght); } // common func end ?>