This commit is contained in:
2023-04-12 13:42:42 +08:00
parent 6eb70b9671
commit 3a702821ed
2 changed files with 28 additions and 7 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+27 -6
View File
@@ -81,7 +81,7 @@ function show_index()
<tr class="border border-green-600"> <tr class="border border-green-600">
<th class="border border-green-600 w-100 text-center">名称</th> <th class="border border-green-600 w-100 text-center">名称</th>
<th class="border border-green-600 w-30 text-center">大小</th> <th class="border border-green-600 w-30 text-center">大小</th>
<th class="border border-green-600 w-30 text-center">状态</th> <th class="border border-green-600 w-40 text-center">状态</th>
<th class="border border-green-600 w-200 text-center">链接</th> <th class="border border-green-600 w-200 text-center">链接</th>
</tr> </tr>
</thead> </thead>
@@ -245,7 +245,7 @@ function api_test()
function api_upload() function api_upload()
{ {
$web = "https://demo.winxg.com"; $web = "https://demo.winxg.com";
$url = "https://telegra.ph/upload"; $url = "https://telegra.ph/upload";
$filePath = $_FILES["file"]["tmp_name"]; $filePath = $_FILES["file"]["tmp_name"];
$ch = curl_init(); $ch = curl_init();
@@ -260,17 +260,21 @@ function api_upload()
$jsonArr = json_decode($response, true); $jsonArr = json_decode($response, true);
$src = $jsonArr[0]["src"] ?? ""; $src = $jsonArr[0]["src"] ?? "";
$uuid = uniqid();
$db = new SQLite3('data.db');
$db->exec("INSERT INTO files (uuid, src) VALUES ('{$uuid}', '{$src}')");
$db->close();
echo_json([ echo_json([
"code" => empty($src) ? 1 : 0, "code" => empty($src) ? 1 : 0,
"msg" => "", "msg" => "",
"data" => [ "data" => [
"id" => $_POST["id"], "id" => $_POST["id"],
"src" => $web . $src "src" => $web . "/file/{$uuid}"
] ]
]); ]);
} }
// api func end // api func end
@@ -281,12 +285,29 @@ function api_upload()
// common func start // common func start
function init() function init()
{ {
$db = new SQLite3('data.db');
// 创建表
$db->exec('CREATE TABLE IF NOT EXISTS files (id INTEGER PRIMARY KEY, uuid TEXT, src TEXT)');
$db->close();
define("BASE_PATH", __DIR__ . "/../"); define("BASE_PATH", __DIR__ . "/../");
define("CONFIG_PATH", BASE_PATH . "/./config/"); define("CONFIG_PATH", BASE_PATH . "/./config/");
define("PUBLIC_PATH", BASE_PATH . "/./public/"); define("PUBLIC_PATH", BASE_PATH . "/./public/");
empty($_SERVER['REQUEST_URI']) || $_SERVER['REQUEST_URI'] == "/" && $_SERVER['REQUEST_URI'] = "/index"; empty($_SERVER['REQUEST_URI']) || $_SERVER['REQUEST_URI'] == "/" && $_SERVER['REQUEST_URI'] = "/index";
check_api(); check_api();
if (str_starts_with($_SERVER['REQUEST_URI'], "/file")) {
$id = explode("/", $_SERVER['REQUEST_URI'])[2] ?? "";
$results = $db->query("SELECT * FROM files WHERE uuid='{$id}' LIMIT 1");
$row = $results->fetchArray();
$db->close();
var_dump($row['src']);
die;
}
} }
function get_page_title() function get_page_title()