/
/
home
/
u523034047
/
domains
/
nainitalfloweritech.com
/
public_html
/
admin
Server: in-mum-web1112.main-hosting.eu (62.72.28.111)
You: 216.73.216.89
PHP 8.3.16
Dir:
/home/u523034047/domains/nainitalfloweritech.com/public_html/admin
Edit:
/home/u523034047/domains/nainitalfloweritech.com/public_html/admin/update-image3.php
<?php session_start(); include('include/config.php'); include('include/admin-menu.php'); if (empty($_SESSION['alogin'])) { header('Location: index.php'); exit(); } $pid = intval($_GET['id']); /* ===== UPDATE PRODUCT IMAGE 3 ===== */ if (isset($_POST['submit']) && isset($_FILES['productimage3'])) { $imgName = $_FILES['productimage3']['name']; $tmpName = $_FILES['productimage3']['tmp_name']; // Fetch old image $stmt = $con->prepare("SELECT productImage3 FROM products WHERE id=?"); $stmt->bind_param("i", $pid); $stmt->execute(); $old = $stmt->get_result()->fetch_assoc(); $dir = "productimages/$pid"; if (!is_dir($dir)) { mkdir($dir, 0777, true); } // Delete old image if (!empty($old['productImage3']) && file_exists("$dir/".$old['productImage3'])) { unlink("$dir/".$old['productImage3']); } // Upload new image move_uploaded_file($tmpName, "$dir/".$imgName); // Update DB $stmt = $con->prepare("UPDATE products SET productImage3=? WHERE id=?"); $stmt->bind_param("si", $imgName, $pid); $_SESSION['msg'] = $stmt->execute() ? "Product image updated successfully!" : "Image update failed!"; header("Location: update-image3.php?id=".$pid); exit(); } /* ===== FETCH PRODUCT ===== */ $stmt = $con->prepare("SELECT productName, productImage3 FROM products WHERE id=?"); $stmt->bind_param("i", $pid); $stmt->execute(); $row = $stmt->get_result()->fetch_assoc(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Update Product Image 3 | Admin</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" rel="stylesheet"> <style> body{ background:linear-gradient(135deg,#667eea,#764ba2); min-height:100vh; font-family:'Segoe UI',sans-serif; } .card-box{ background:#fff; border-radius:12px; box-shadow:0 15px 40px rgba(0,0,0,.2); padding:25px; max-width:700px; margin:auto; } .form-control{ height:45px; } .preview-img{ max-width:100%; border-radius:10px; box-shadow:0 5px 15px rgba(0,0,0,.2); } </style> </head> <body> <div class="container py-5"> <div class="card-box"> <h4 class="mb-3"> <i class="fa fa-image"></i> Update Product Image 3 </h4> <?php if(!empty($_SESSION['msg'])){ ?> <div class="alert alert-success text-center"> <?php echo $_SESSION['msg']; $_SESSION['msg']=""; ?> </div> <?php } ?> <form method="post" enctype="multipart/form-data"> <div class="mb-3"> <label class="form-label">Product Name</label> <input type="text" class="form-control" value="<?php echo htmlentities($row['productName']); ?>" readonly> </div> <div class="mb-3 text-center"> <label class="form-label d-block">Current Image</label> <img src="productimages/<?php echo $pid; ?>/<?php echo htmlentities($row['productImage3']); ?>" class="preview-img mb-3"> </div> <div class="mb-3"> <label class="form-label">Upload New Image</label> <input type="file" name="productimage3" class="form-control" required> </div> <button type="submit" name="submit" class="btn btn-primary w-100"> <i class="fa fa-upload"></i> Update Image </button> <a href="edit-products.php?id=<?php echo $pid; ?>" class="btn btn-link w-100 mt-2"> ← Back to Edit Product </a> </form> </div> </div> </body> </html>
Ukuran: 3.6 KB