修改主页日志日期问题

This commit is contained in:
2025-08-05 03:01:02 +08:00
parent c25ae6bdca
commit ef2c204bae
5 changed files with 110 additions and 13 deletions

13
public/blog/master/index.php Executable file
View File

@@ -0,0 +1,13 @@
<title>master</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
textarea { width: 400px; height: 150px; }
input[type="submit"] { padding: 10px 20px; font-size: 16px; cursor: pointer; }
</style>
<form action="post_data.php" method="POST">
<textarea name="data" placeholder="在这里输入数据..."></textarea>
<br>
<br>
<input type="submit" value="保存数据">
</form>

1
public/blog/master/index.txt Executable file
View File

@@ -0,0 +1 @@
{2025/07/30};{"第一篇文章"}

View File

@@ -0,0 +1,34 @@
<?php
// 1. 定义要写入的文件路径
$file = './index.txt';
// 2. 检查是否通过 POST 请求接收到了数据
// 'data' 是表单中 <textarea> 标签的 name 属性
if (isset($_POST['data']) && !empty($_POST['data'])) {
// 自动获取当前日期和时间
$date = date('Y/m/d');
// 获取你在网页输入框中写的数据
$data = $_POST['data'];
// 3. 构建完整的单行内容,格式为 {日期};{数据},并以换行符 \n 结尾
$content = "{" . $date . "};" . "{" . '"' . $data . '"' . "}" . "\n";
// 4. 将内容追加到文件末尾
$result = file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
// 5. 检查是否写入成功并给出反馈
if ($result !== false) {
echo "数据已成功写入到 " . $file . " 文件。你可以 <a href='https://open-ww3-project.ww3.tw/blog/master/'>返回</a>。";
} else {
echo "写入文件失败,请检查文件权限。";
}
} else {
// 如果没有接收到数据,返回错误信息
echo "没有接收到任何数据。请 <a href='https://open-ww3-project.ww3.tw/blog/master/'>返回</a> 重新输入。";
}
?>