-- 创建书籍表
CREATE TABLE books (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
file_count INT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- 创建书籍文件表
CREATE TABLE book_files (
id INT AUTO_INCREMENT PRIMARY KEY,
book_id INT NOT NULL,
filename VARCHAR(255) NOT NULL,
file_type VARCHAR(100) NOT NULL,
file_size INT DEFAULT 0,
content LONGBLOB,
content_text LONGTEXT,
sort_order INT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (book_id) REFERENCES books(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
Script file validation failed: potentially dangerous code pattern detected in php file 报错解决办法
Download FileZilla Client for Windows (64bit x86)
用ipad测试了可以打开
<?php
// bookapi/config.php
// 注意:不要在这里设置Content-Type,让每个API自行设置
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
// 处理预检请求
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
exit(0);
}
// 开启错误报告(仅用于调试环境)
error_reporting(E_ALL);
ini_set('display_errors', 1);
function loadEnv($path) {
if (!file_exists($path)) return;
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos($line, '=') !== false && strpos($line, '#') !== 0) {
list($key, $value) = explode('=', $line, 2);
$_ENV[trim($key)] = trim($value);
}
}
}
loadEnv(__DIR__ . '/.env');
$host = $_ENV['DB_HOST'] ?? 'sql100.byetcluster.com';
$dbname = $_ENV['DB_NAME'] ?? 'if0_39801986_keyinfo';
$username = $_ENV['DB_USER'] ?? 'if0_39801986';
$password = $_ENV['DB_PASS'] ?? '密码';
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
} catch(PDOException $e) {
error_log("Database connection failed: " . $e->getMessage());
header('Content-Type: application/json');
echo json_encode(['success' => false, 'message' => '数据库连接失败: ' . $e->getMessage()]);
exit;
}
?>
<?php
// bookapi/load_book.php
include 'config.php';
header('Content-Type: application/json'); // 添加这行
if (!isset($_GET['id'])) {
echo json_encode(['success' => false, 'message' => '缺少书籍ID']);
exit;
}
try {
$bookId = intval($_GET['id']);
// 获取书籍信息
$stmt = $pdo->prepare("SELECT id, name, file_count, created_at, updated_at FROM books WHERE id = ?");
$stmt->execute([$bookId]);
$book = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$book) {
echo json_encode(['success' => false, 'message' => '书籍不存在']);
exit;
}
// 获取文件列表
$stmt = $pdo->prepare("SELECT id, filename, file_type, file_size, sort_order FROM book_files WHERE book_id = ? ORDER BY sort_order");
$stmt->execute([$bookId]);
$files = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode(['success' => true, 'book' => $book, 'files' => $files]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'message' => '加载书籍失败: ' . $e->getMessage()]);
}
?>
读取部分
jobfinder.html里
async function loadConfigFromDatabase() {
try {
const response = await fetch('./keyinfoapi/get_config.php');
const result = await response.json();
console.info('result:', result);
if (result.success) {
API_KEYS.deepseek = result.data.deepseek_api_key || "your-placeholder-key";
PERSONAL_INFO = result.data.personal_info || "默认个人信息...";
}
} catch (error) {
console.error('获取配置失败:', error);
// 使用默认值
API_KEYS.deepseek = "your-placeholder-key";
PERSONAL_INFO = "默认个人信息...";
}
}
<?php
// keyinfoapi/get_config.php
include 'config.php';
try {
$stmt = $pdo->query("SELECT config_key, config_value FROM user_configs");
$configs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$result = [];
foreach ($configs as $config) {
$result[$config['config_key']] = $config['config_value'];
}
echo json_encode(['success' => true, 'data' => $result]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'message' => '获取配置失败: ' . $e->getMessage()]);
}
?>
<?php
// keyinfoapi/config.php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
// 处理预检请求
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
exit(0);
}
function loadEnv($path) {
if (!file_exists($path)) return;
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos($line, '=') !== false && strpos($line, '#') !== 0) {
list($key, $value) = explode('=', $line, 2);
$_ENV[trim($key)] = trim($value);
}
}
}
loadEnv(__DIR__ . '../.env');
$host = $_ENV['DB_HOST'] ?? 'sql100.byetcluster.com';
$dbname = $_ENV['DB_NAME'] ?? 'if0_39801986_keyinfo';
$username = $_ENV['DB_USER'] ?? 'if0_39801986';
$password = $_ENV['DB_PASS'] ?? '密码';
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
error_log("Database connection failed: " . $e->getMessage());
echo json_encode(['success' => false, 'message' => '数据库连接失败']);
exit;
}
?>