update
This commit is contained in:
+20
-19
@@ -263,7 +263,7 @@ function api_upload()
|
|||||||
|
|
||||||
$uuid = uniqid();
|
$uuid = uniqid();
|
||||||
|
|
||||||
exec_db("INSERT INTO files (uuid, src) VALUES ('{$uuid}', '{$src}')");
|
exec_db("INSERT INTO files (uuid, src) VALUES ('{$uuid}', '{$src}')");
|
||||||
|
|
||||||
echo_json([
|
echo_json([
|
||||||
"code" => empty($src) ? 1 : 0,
|
"code" => empty($src) ? 1 : 0,
|
||||||
@@ -289,7 +289,7 @@ function init()
|
|||||||
define("DATA_PATH", BASE_PATH . "/./data/");
|
define("DATA_PATH", BASE_PATH . "/./data/");
|
||||||
|
|
||||||
inti_db();
|
inti_db();
|
||||||
|
|
||||||
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();
|
||||||
@@ -297,10 +297,12 @@ 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 = query_db("SELECT * FROM files WHERE uuid='{$id}' LIMIT 1");
|
$stmt = get_db()->prepare("SELECT * FROM files WHERE uuid=:uuid LIMIT 1");
|
||||||
$row = $results->fetchArray();
|
$stmt->bindParam(':uuid', $id);
|
||||||
|
|
||||||
if(empty($row['stc'])){
|
$row = $stmt->fetch();
|
||||||
|
|
||||||
|
if (empty($row['stc'])) {
|
||||||
echo_json([
|
echo_json([
|
||||||
"code" => 1,
|
"code" => 1,
|
||||||
"msg" => "图片不存在",
|
"msg" => "图片不存在",
|
||||||
@@ -333,23 +335,22 @@ function show_page()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function exec_db($sql){
|
function get_db()
|
||||||
$db = new SQLite3(DATA_PATH . 'data.db');
|
{
|
||||||
// 创建表
|
$db = new PDO('sqlite:' . DATA_PATH . 'data.db');
|
||||||
|
|
||||||
|
return $db;
|
||||||
|
}
|
||||||
|
|
||||||
|
function exec_db($sql)
|
||||||
|
{
|
||||||
|
$db = get_db();
|
||||||
|
|
||||||
$db->exec($sql);
|
$db->exec($sql);
|
||||||
$db->close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function query_db($sql){
|
function inti_db()
|
||||||
$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)');
|
exec_db('CREATE TABLE IF NOT EXISTS files (id INTEGER PRIMARY KEY, uuid TEXT, src TEXT)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user