« Back to History
post_image_folder_manage.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once __DIR__ . '/../config.php'; $pdo = db_connect(); /* --------- SAVE / UPDATE --------- */ $msg = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $post_id = (int)($_POST['post_id'] ?? 0); $folder = trim($_POST['folder_name'] ?? ''); if ($post_id > 0 && $folder !== '') { // upsert $chk = $pdo->prepare("SELECT post_id FROM post_image_folder WHERE post_id=?"); $chk->execute([$post_id]); if ($chk->fetch()) { $pdo->prepare(" UPDATE post_image_folder SET folder_name=?, updated_at=NOW() WHERE post_id=? ")->execute([$folder, $post_id]); } else { $pdo->prepare(" INSERT INTO post_image_folder (post_id, folder_name, created_at, updated_at) VALUES (?, ?, NOW(), NOW()) ")->execute([$post_id, $folder]); } $msg = '✅ Folder mapping saved'; } else { $msg = '❌ Post aur folder dono select karo'; } } /* --------- FETCH POSTS --------- */ $posts = $pdo->query(" SELECT id, title FROM posts ORDER BY created_at DESC ")->fetchAll(PDO::FETCH_ASSOC); /* --------- FETCH EXISTING MAPPING --------- */ $map = []; $q = $pdo->query("SELECT post_id, folder_name FROM post_image_folder"); foreach ($q as $r) { $map[$r['post_id']] = $r['folder_name']; } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Post Image Folder Control</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body{font-family:system-ui;background:#f4f6f8;margin:0} .wrap{max-width:1100px;margin:30px auto} .card{background:#fff;border:1px solid #ddd;border-radius:6px;padding:20px} h2{margin-top:0} table{width:100%;border-collapse:collapse} th,td{padding:10px;border-bottom:1px solid #eee;text-align:left} select,input{padding:6px;width:100%} button{padding:6px 12px;background:#2271b1;color:#fff;border:none;border-radius:4px} .notice{margin-bottom:10px;font-weight:600} .small{color:#666;font-size:13px} </style> </head> <body> <div class="wrap"> <div class="card"> <h2>Post → Image Folder Mapping</h2> <?php if ($msg): ?> <p class="notice"><?= htmlspecialchars($msg) ?></p> <?php endif; ?> <form method="post"> <table> <thead> <tr> <th style="width:45%">Post (Shayari Page)</th> <th style="width:35%">Image Folder Name</th> <th style="width:20%">Action</th> </tr> </thead> <tbody> <tr> <td> <select name="post_id" required> <option value="">— Select Post —</option> <?php foreach ($posts as $p): ?> <option value="<?= $p['id'] ?>"> <?= htmlspecialchars($p['title']) ?> </option> <?php endforeach; ?> </select> </td> <td> <input name="folder_name" placeholder="e.g. jija_sali_img"> </td> <td> <button type="submit">Save</button> </td> </tr> </tbody> </table> </form> <hr> <h3>Existing Folder Mappings</h3> <table> <thead> <tr> <th>Post</th> <th>Folder</th> </tr> </thead> <tbody> <?php foreach ($map as $pid => $fname): ?> <tr> <td> <?php foreach ($posts as $p) { if ($p['id'] == $pid) { echo htmlspecialchars($p['title']); break; } } ?> </td> <td><code><?= htmlspecialchars($fname) ?></code></td> </tr> <?php endforeach; ?> </tbody> </table> <p class="small"> Folder path assumed: <b>/public_html/uploads/{folder_name}/</b> </p> </div> </div> </body> </html>