⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.124
Server IP:
50.28.103.30
Server:
Linux host.jcukjv-lwsites.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
Server Software:
nginx/1.28.0
PHP Version:
8.3.12
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
www
/
wwwroot
/
china-democracyparty.com
/
5
/
View File Name :
addblog.php
<?php // add.php // 0. 开启 Session,并判断是否已登录 session_start(); if (empty($_SESSION['admin_logged'])) { // 没有登录就跳回后台主页/登录页 header('Location: admin.php'); exit; } // 1. 设置为洛杉矶时间(美西时间) date_default_timezone_set('America/Los_Angeles'); // 2. 连接数据库 require_once __DIR__ . '/sql.php'; // 是否有提交行为 if ($_SERVER['REQUEST_METHOD'] === 'POST') { // 接收表单数据 $title = $_POST['title'] ?? ''; $description = $_POST['description'] ?? ''; $content = $_POST['content'] ?? ''; // 默认图片路径为空 $image_path = ""; // 3. 处理图片上传 if (!empty($_FILES['image']['name'])) { $uploadDir = __DIR__ . '/uploads/'; if (!is_dir($uploadDir)) { mkdir($uploadDir, 0755, true); } $filename = time() . '_' . basename($_FILES['image']['name']); $savePath = $uploadDir . $filename; if (move_uploaded_file($_FILES['image']['tmp_name'], $savePath)) { // 存数据库用的路径 $image_path = 'uploads/' . $filename; } } // 4. 使用当地时间插入数据库 $created_at = date('Y-m-d H:i:s'); // ✔ 当地时间(洛杉矶) $sql = "INSERT INTO blogs (title, description, content, image, views, created_at) VALUES (?, ?, ?, ?, 0, ?)"; $stmt = $conn->prepare($sql); $stmt->bind_param("sssss", $title, $description, $content, $image_path, $created_at); if ($stmt->execute()) { header("Location: admin.php?msg=success"); exit; } else { $error = "插入失败: " . $conn->error; } } ?> <!DOCTYPE html> <html> <head> <title>后台管理 - 发布博客</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.1.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script> </head> <body> <main> <div class="container"> <header class="d-flex flex-wrap align-items-center justify-content-between py-3 mb-4 border-bottom"> <a href="/" class="text-dark text-decoration-none"> <span class="fs-4">后台管理系统</span> </a> <div class="text-end"> <a href="add.php" class="btn btn-outline-primary me-2">Add Blog</a> <a href="logout.php" class="btn btn-primary">Log Out</a> </div> </header> </div> <div class="container mt-3"> <h3>发布一条博客信息</h3> <?php if (!empty($_GET['msg']) && $_GET['msg']==='success'): ?> <div class="alert alert-success">提交成功!</div> <?php endif; ?> <?php if (!empty($error)): ?> <div class="alert alert-danger"><?= htmlspecialchars($error) ?></div> <?php endif; ?> <form action="" method="post" enctype="multipart/form-data"> <!-- 标题 --> <div class="mb-3 mt-3"> <label class="form-label">标题</label> <input type="text" class="form-control" name="title" placeholder="Enter title" required> </div> <!-- 描述 --> <div class="mb-3 mt-3"> <label class="form-label">描述</label> <textarea class="form-control" rows="3" name="description" required></textarea> </div> <!-- 内容 --> <div class="mb-3 mt-3"> <label class="form-label">内容</label> <textarea class="form-control" rows="6" name="content" required></textarea> </div> <!-- 图片 --> <div class="mb-3 mt-3"> <label class="form-label">封面图片</label><br> <input type="file" name="image"> </div> <button type="submit" class="btn btn-primary">提交</button> </form> </div> </main> </body> </html>