📁 File Manager
Editing:
/home/wedigitalindia/public_html/jaybalajiassociates.com/admin/editpartner.php
<?php include("connection.php"); ini_set('display_errors', 1); error_reporting(E_ALL); if (!isset($_GET['id'])) { header("Location: viewpartner.php"); exit; } $id = (int)$_GET['id']; // Fetch existing data $query = mysqli_query($con, "SELECT * FROM partner_logo WHERE id = $id"); $data = mysqli_fetch_assoc($query); if (!$data) { header("Location: viewpartner.php"); exit; } $error_message = ''; if (isset($_POST['form1'])) { if (!empty($_FILES['logo']['name'])) { $allowed_exts = ['jpg', 'jpeg', 'png', 'gif', 'webp']; $file_name = $_FILES['logo']['name']; $file_tmp = $_FILES['logo']['tmp_name']; $ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION)); if (!in_array($ext, $allowed_exts)) { $error_message = "Invalid image format."; } else { $new_name = 'partner-' . date('YmdHis') . '-' . uniqid() . '.' . $ext; $upload_path = 'assets/images/partner_logo/' . $new_name; if (move_uploaded_file($file_tmp, $upload_path)) { // Delete old file $old_file = 'assets/images/partner_logo/' . $data['logo']; if (!empty($data['logo']) && file_exists($old_file)) { unlink($old_file); } // Update DB $stmt = $con->prepare("UPDATE partner_logo SET logo = ? WHERE id = ?"); $stmt->bind_param("si", $new_name, $id); $stmt->execute(); header("Location: viewpartner.php"); exit; } else { $error_message = "Logo upload failed."; } } } else { $error_message = "Please select a new logo."; } } ?> <?php include("header.php"); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Edit Partner Logo</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="assets/css/bootstrap.min.css" rel="stylesheet"> <link href="assets/css/icons.min.css" rel="stylesheet"> <link href="assets/css/app.min.css" rel="stylesheet"> <style> .dropzone { border: 2px dashed #ccc; padding: 40px; border-radius: 10px; text-align: center; background: #f9f9f9; position: relative; } .dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; } .preview img { max-width: 160px; border: 1px solid #ddd; padding: 5px; border-radius: 6px; background: #fff; } </style> </head> <body data-sidebar="dark"> <div id="layout-wrapper"> <div class="page-content" style="width:80%;margin-left:260px;"> <div class="container"> <!-- Title --> <div class="row mb-3"> <div class="col-12"> <h4>Edit Partner Logo</h4> </div> </div> <div class="card"> <div class="card-body"> <?php if (!empty($error_message)) { ?> <div class="alert alert-danger"><?= $error_message; ?></div> <?php } ?> <form method="POST" enctype="multipart/form-data"> <input type="hidden" name="form1" value="1"> <!-- Existing Logo --> <div class="mb-4"> <label class="form-label">Current Logo</label><br> <img src="assets/images/partner_logo/<?= htmlspecialchars($data['logo']); ?>" alt="Current Logo"> </div> <!-- Upload New --> <label class="form-label">Replace Logo</label> <div class="dropzone mb-3"> <input type="file" name="logo" id="logoInput"> <i class="bx bxs-cloud-upload" style="font-size:40px;"></i> <h5>Click or Drop New Logo</h5> </div> <!-- New Preview --> <div class="preview mb-4" id="previewBox"></div> <div class="text-center"> <button type="submit" class="btn btn-primary"> Update Logo </button> <a href="viewpartner.php" class="btn btn-danger"> Cancel </a> </div> </form> </div> </div> </div> </div> </div> <script> const input = document.getElementById('logoInput'); const previewBox = document.getElementById('previewBox'); input.addEventListener('change', () => { previewBox.innerHTML = ''; const file = input.files[0]; if (file && file.type.startsWith('image/')) { const reader = new FileReader(); reader.onload = e => { const img = document.createElement('img'); img.src = e.target.result; previewBox.appendChild(img); }; reader.readAsDataURL(file); } }); </script> <?php include("footer.php"); ?> </body> </html>
Save
Cancel