This commit is contained in:
2023-04-12 14:47:30 +08:00
parent b96e5f8dcb
commit 8745f9ad79
2 changed files with 54 additions and 28 deletions
+51 -28
View File
@@ -248,8 +248,7 @@ function api_test()
function api_upload()
{
$web = "https://demo.winxg.com";
$web = get_config('common', 'web');
$url = "https://telegra.ph/upload";
$filePath = $_FILES["file"]["tmp_name"];
$ch = curl_init();
@@ -298,32 +297,7 @@ function init()
check_api();
if (str_starts_with($_SERVER['REQUEST_URI'], "/file")) {
$id = explode("/", $_SERVER['REQUEST_URI'])[2] ?? "";
$stmt = get_db()->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;
}
check_file();
}
function get_page_title()
@@ -377,5 +351,54 @@ function uniqidReal($lenght = 13)
return substr(bin2hex($bytes), 0, $lenght);
}
function check_file()
{
if (str_starts_with($_SERVER['REQUEST_URI'], "/file")) {
$id = explode("/", $_SERVER['REQUEST_URI'])[2] ?? "";
$stmt = get_db()->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_config($file, $path)
{
if (!file_exists(CONFIG_PATH . $file . ".json")) {
return "";
}
$conf = file_get_contents(CONFIG_PATH . $file . ".json");
$arr = json_decode($conf, true);
$value = $arr;
foreach(explode(".", $path) as $p){
$value = $value[$p] ?? "";
if (!$value) break;
}
return $value;
}
// common func end
?>