52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
<?php
|
|
// 通用函数
|
|
|
|
/**
|
|
* 获取配置值
|
|
*/
|
|
function getConfig($key, $default = '') {
|
|
global $db;
|
|
$stmt = $db->prepare("SELECT value FROM config WHERE key = ?");
|
|
$stmt->execute([$key]);
|
|
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
return $result ? $result['value'] : $default;
|
|
}
|
|
|
|
/**
|
|
* 更新配置值
|
|
*/
|
|
function updateConfig($key, $value) {
|
|
global $db;
|
|
$stmt = $db->prepare("INSERT OR REPLACE INTO config (key, value) VALUES (?, ?)");
|
|
return $stmt->execute([$key, $value]);
|
|
}
|
|
|
|
/**
|
|
* 格式化文件大小
|
|
*/
|
|
function formatFileSize($bytes) {
|
|
if ($bytes >= 1073741824) {
|
|
return number_format($bytes / 1073741824, 2) . ' GB';
|
|
} elseif ($bytes >= 1048576) {
|
|
return number_format($bytes / 1048576, 2) . ' MB';
|
|
} elseif ($bytes >= 1024) {
|
|
return number_format($bytes / 1024, 2) . ' KB';
|
|
} else {
|
|
return $bytes . ' B';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 检查是否已登录
|
|
*/
|
|
function isLoggedIn() {
|
|
return isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true;
|
|
}
|
|
|
|
/**
|
|
* 安全输出 HTML
|
|
*/
|
|
function e($string) {
|
|
return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
|
|
}
|