init
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
require_once 'auth.php';
|
||||
require_once '../includes/db.php';
|
||||
|
||||
// 处理文件上传
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (!isset($_FILES['apk_file']) || $_FILES['apk_file']['error'] !== UPLOAD_ERR_OK) {
|
||||
die('文件上传失败');
|
||||
}
|
||||
|
||||
$file = $_FILES['apk_file'];
|
||||
$version = $_POST['version'] ?? '';
|
||||
$description = $_POST['description'] ?? '';
|
||||
|
||||
// 验证文件类型
|
||||
$ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
|
||||
if ($ext !== 'apk') {
|
||||
die('只允许上传 APK 文件');
|
||||
}
|
||||
|
||||
// 生成唯一文件名
|
||||
$filename = time() . '_' . $file['name'];
|
||||
$target_path = '../data/apps/' . $filename;
|
||||
|
||||
// 移动文件
|
||||
if (!move_uploaded_file($file['tmp_name'], $target_path)) {
|
||||
die('文件保存失败');
|
||||
}
|
||||
|
||||
// 插入数据库
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO apps (filename, original_name, version, description, file_size)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
");
|
||||
$stmt->execute([
|
||||
$filename,
|
||||
$file['name'],
|
||||
$version,
|
||||
$description,
|
||||
$file['size']
|
||||
]);
|
||||
|
||||
// 重定向回管理面板
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 如果不是 POST 请求,重定向回管理面板
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
Reference in New Issue
Block a user