File size: 1,551 Bytes
dc45f00 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
<?php
// 设置时区
date_default_timezone_set('Asia/Shanghai');
// 处理错误输出
ini_set('display_errors', 'Off');
error_reporting(E_ALL);
ini_set('log_errors', 'On');
ini_set('error_log', '/dev/stderr');
// 设置 Content-Type 为 JSON(针对 API 请求)
if (in_array(basename($_SERVER['REQUEST_URI']), [
'delete.php',
'images.php',
'videos.php',
'upload.php'
])) {
header('Content-Type: application/json');
}
// 处理静态文件
if (preg_match('/\.(css|js|png|jpg|jpeg|gif|ico|webp|mp4)$/', $_SERVER['REQUEST_URI'])) {
return false; // 让 PHP 内置服务器处理静态文件
}
// 根据请求路径加载对应的 PHP 文件
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$file = ltrim($path, '/');
// API 路由映射
$apiRoutes = [
'delete.php' => 'delete.php',
'images.php' => 'images.php',
'img.php' => 'img.php',
'upload.php' => 'upload.php',
'videos.php' => 'videos.php'
];
// 处理 API 请求
if (isset($apiRoutes[$file])) {
require __DIR__ . '/' . $apiRoutes[$file];
return true;
}
// 如果是空路径或根路径,返回 index.html
if ($file === '' || $file === 'index.html') {
require __DIR__ . '/index.html';
return true;
}
// 如果文件存在且是 PHP 文件,则执行它
if (file_exists(__DIR__ . '/' . $file) && preg_match('/\.php$/', $file)) {
require __DIR__ . '/' . $file;
return true;
}
// 默认返回 index.html
require __DIR__ . '/index.html';
return true; |