Files
MoYuBan/api/upload_text.php
2025-11-18 14:18:28 +08:00

37 lines
1.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// 接收用户提交的文案,保存到 texts_pending 目录JSON文件
header('Content-Type: text/html; charset=utf-8');
$pendingDir = __DIR__ . '/../texts_pending';
if (!is_dir($pendingDir)) {
@mkdir($pendingDir, 0777, true);
}
function html($s){ return htmlspecialchars($s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); }
$title = isset($_POST['title']) ? trim($_POST['title']) : '';
$content = isset($_POST['content']) ? trim($_POST['content']) : '';
if ($content === '') {
echo '<div style="padding:16px;border:1px solid #e33;border-radius:8px;max-width:640px;margin:24px auto;">';
echo '<p>文案内容不能为空。</p><p><a href="../upload_text.php">返回文案投稿页</a></p>';
echo '</div>';
exit;
}
$name = 'text_' . date('Ymd_His') . '_' . mt_rand(1000,9999) . '.json';
$data = [
'title' => $title,
'content' => $content,
'uploaded_at' => date('c'),
];
@file_put_contents($pendingDir . '/' . $name, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
echo '<div style="padding:16px;border:1px solid #e33;border-radius:8px;max-width:640px;margin:24px auto;">';
echo '<p>提交成功!文案已保存到待处理目录。</p>';
if ($title !== '') echo '<p>标题:' . html($title) . '</p>';
echo '<p>内容:</p><pre style="white-space:pre-wrap;">' . html($content) . '</pre>';
echo '<p><a href="../upload_text.php">继续提交</a> 或 <a href="../index.php">返回首页</a></p>';
echo '</div>';
?>