修改主页日志日期问题

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

View File

@@ -33,7 +33,7 @@
<tbody>
<tr>
<td id="td_logs">2025.07.30</td>
<td id="td_logs_content">新增post、模块这是第一篇<a href="https://ww3.tw/blog/md/post/s/2025/7/30/">文章</a></td>
<td id="td_logs_content">新增post、模块这是第一篇<a href="https://ww3.tw/blog/md/post/s/2025/07/30/">文章</a></td>
</tr>
<tr>
@@ -77,18 +77,33 @@
</font>
</div>
<!-- 屑站日志 -->
<div id="js_date"></div>
<script>
</script>
<br>
<br>
<div id="post_content">
<?php
include "./read_file.php";
?>
</div>
</body>
</html>
<?php
include "../static/html/black-block.html";
?>
<style>
#open-ww3-project-img
{
overflow: auto;
/* up、right、down、left */
margin: -354px 0px 0px 1035px;
}
#post_content
{
/*text-align: center;*/
height: 500px;
width: 450px;
color: rgb(202, 202, 202);
overflow: auto;
/* up、right、down、left */
margin: -250px 0px 0px 700px;
}
body
{
background-color: rgba(147, 185, 255, 0.644);
@@ -142,9 +157,10 @@
padding-left: 10px;
padding-bottom: 5px;
}
</style>
#js_date{
color: rgb(55, 0, 255);
font-size: 200%;
}
</style>
<!-- 专属php代码部分 -->
<?php
include "../static/html/black-block.html";
?>
<!-- php部分 -->

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> 重新输入。";
}
?>

33
public/blog/read_file.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
$file = './master/index.txt'; //定义文件的位置
if (file_exists($file)) {
$content = file_get_contents($file);
//分割输出内容
$lines = explode("\n",$content);
//逐行解析
foreach ($lines as $line) {
if (preg_match('/\{([^}]+)\};\{"([^"]+)\"}/', $line, $matches)) {
$data = $matches[1]; // 提取出数据
$title = $matches[2]; // 提取出标题
echo "文章如下: ";
// 输出提取到的内容
echo "<br><br>";
echo "" . $data . "\n";
echo "" . $title . "\n";
echo "<a href='https://ww3.tw/blog/md/post/s/$data' style='color: black;'> 跳转页面</a>";
//echo '链接 (URL): <a herf="">链接</a>';
}
}
//输出内容
//echo "文件 '{$file}' 的内容是: <br><br>\n\n";
//echo $content;
} else {
echo "错误: 文件 '$file' 不存在 ";
}
?>