Files
php_app_downloader/admin/config.php
T
2026-06-24 18:17:13 +08:00

113 lines
4.2 KiB
PHP

<?php
require_once 'auth.php';
require_once '../includes/db.php';
require_once '../includes/functions.php';
$success = '';
$error = '';
// 处理表单提交
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$site_title = $_POST['site_title'] ?? '';
$site_description = $_POST['site_description'] ?? '';
// 更新基本配置
updateConfig('site_title', $site_title);
updateConfig('site_description', $site_description);
// 处理 Logo 上传
if (isset($_FILES['logo']) && $_FILES['logo']['error'] === UPLOAD_ERR_OK) {
$logo = $_FILES['logo'];
$ext = strtolower(pathinfo($logo['name'], PATHINFO_EXTENSION));
// 验证文件类型
if (in_array($ext, ['jpg', 'jpeg', 'png', 'gif'])) {
$logo_filename = 'logo_' . time() . '.' . $ext;
$logo_path = '../data/uploads/' . $logo_filename;
if (move_uploaded_file($logo['tmp_name'], $logo_path)) {
// 删除旧 logo(如果在 data/uploads/ 目录)
$old_logo = getConfig('logo_path');
if (strpos($old_logo, 'data/uploads/') === 0) {
$old_logo_path = '../' . $old_logo;
if (file_exists($old_logo_path)) {
unlink($old_logo_path);
}
}
updateConfig('logo_path', 'data/uploads/' . $logo_filename);
$success = '配置保存成功!';
} else {
$error = 'Logo 上传失败';
}
} else {
$error = 'Logo 只支持 JPG、PNG、GIF 格式';
}
} else {
$success = '配置保存成功!';
}
}
// 获取当前配置
$site_title = getConfig('site_title', 'OPS 运营管理系统');
$site_description = getConfig('site_description', '点击下方按钮下载移动端 APP');
$logo_path = getConfig('logo_path', 'logo.png');
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>网站配置</title>
<link rel="stylesheet" href="../assets/admin.css">
</head>
<body>
<div class="admin-container">
<header class="admin-header">
<h1>网站配置</h1>
<div class="header-actions">
<a href="dashboard.php" class="btn btn-secondary">返回管理面板</a>
<a href="change_password.php" class="btn btn-secondary">修改密码</a>
<a href="logout.php" class="btn btn-secondary">退出</a>
</div>
</header>
<main class="admin-main">
<?php if ($success): ?>
<div class="alert alert-success"><?php echo e($success); ?></div>
<?php endif; ?>
<?php if ($error): ?>
<div class="alert alert-error"><?php echo e($error); ?></div>
<?php endif; ?>
<section class="config-section">
<h2>基本设置</h2>
<form method="POST" enctype="multipart/form-data" class="config-form">
<div class="form-group">
<label>网站标题 *</label>
<input type="text" name="site_title" value="<?php echo e($site_title); ?>" required>
</div>
<div class="form-group">
<label>软件说明</label>
<textarea name="site_description" rows="4"><?php echo e($site_description); ?></textarea>
</div>
<div class="form-group">
<label>网站 Logo</label>
<div class="logo-preview">
<img src="../<?php echo e($logo_path); ?>" alt="Logo" style="max-width: 200px; max-height: 200px;">
</div>
<input type="file" name="logo" accept="image/jpeg,image/png,image/gif">
<small class="form-hint">支持 JPG、PNG、GIF 格式</small>
</div>
<button type="submit" class="btn btn-primary">保存配置</button>
</form>
</section>
</main>
</div>
</body>
</html>