This commit is contained in:
2023-04-12 14:09:04 +08:00
parent c2249e15dc
commit bdace88adc
+33 -13
View File
@@ -263,9 +263,7 @@ function api_upload()
$uuid = uniqid(); $uuid = uniqid();
$db = new SQLite3(DATA_PATH . 'data.db'); exec_db("INSERT INTO files (uuid, src) VALUES ('{$uuid}', '{$src}')");
$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,
@@ -290,12 +288,7 @@ function init()
define("PUBLIC_PATH", BASE_PATH . "/./public/"); define("PUBLIC_PATH", BASE_PATH . "/./public/");
define("DATA_PATH", BASE_PATH . "/./data/"); define("DATA_PATH", BASE_PATH . "/./data/");
inti_db();
$db = new SQLite3(DATA_PATH . 'data.db');
// 创建表
$db->exec('CREATE TABLE IF NOT EXISTS files (id INTEGER PRIMARY KEY, uuid TEXT, src TEXT)');
$db->close();
empty($_SERVER['REQUEST_URI']) || $_SERVER['REQUEST_URI'] == "/" && $_SERVER['REQUEST_URI'] = "/index"; empty($_SERVER['REQUEST_URI']) || $_SERVER['REQUEST_URI'] == "/" && $_SERVER['REQUEST_URI'] = "/index";
@@ -304,12 +297,19 @@ function init()
if (str_starts_with($_SERVER['REQUEST_URI'], "/file")) { if (str_starts_with($_SERVER['REQUEST_URI'], "/file")) {
$id = explode("/", $_SERVER['REQUEST_URI'])[2] ?? ""; $id = explode("/", $_SERVER['REQUEST_URI'])[2] ?? "";
$results = $db->query("SELECT * FROM files WHERE uuid='{$id}' LIMIT 1"); $results = query_db("SELECT * FROM files WHERE uuid='{$id}' LIMIT 1");
$row = $results->fetchArray(); $row = $results->fetchArray();
$db->close();
var_dump($row['src']); if(empty($row['stc'])){
echo_json([
"code" => 1,
"msg" => "图片不存在",
"data" => []
]);
}
$imgUrl = "https://telegra.ph{$row['src']}";
var_dump($imgUrl);
die; die;
} }
} }
@@ -333,5 +333,25 @@ function show_page()
} }
} }
function exec_db($sql){
$db = new SQLite3(DATA_PATH . 'data.db');
// 创建表
$db->exec($sql);
$db->close();
}
function query_db($sql){
$db = new SQLite3(DATA_PATH . 'data.db');
// 创建表
$results = $db->query($sql);
$db->close();
return $results;
}
function inti_db(){
exec_db('CREATE TABLE IF NOT EXISTS files (id INTEGER PRIMARY KEY, uuid TEXT, src TEXT)');
}
// common func end // common func end
?> ?>