From b05bc7e93343efcd4fa53793a1ce0539b623b6d5 Mon Sep 17 00:00:00 2001 From: Devdatt Bhatt Date: Wed, 20 May 2026 12:30:40 +0000 Subject: [PATCH] updtae --- encoder/app.php | 119 +++++++++++++++++++++++++++++++----------------- 1 file changed, 78 insertions(+), 41 deletions(-) diff --git a/encoder/app.php b/encoder/app.php index 94be23a..ccd16d7 100644 --- a/encoder/app.php +++ b/encoder/app.php @@ -14,7 +14,6 @@ $error_message = ''; // --- 1. Handle Form Submission BEFORE any HTML is sent --- if (isset($_POST['submit'])) { $upload_paths = [ - 'app_und' => '/var/www/html/app_ad.png', 'app_ad' => '/var/www/html/app_ad.png', 'app_logo' => '/var/www/html/app_logo.png' ]; @@ -22,11 +21,25 @@ if (isset($_POST['submit'])) { $errors = []; + // Handle File Deletions (Remove feature) + $to_delete = $_POST['remove_files'] ?? []; + foreach ($to_delete as $file_key => $should_delete) { + if ($should_delete === '1' && isset($upload_paths[$file_key])) { + $path = $upload_paths[$file_key]; + if (file_exists($path)) { + unlink($path); + // Also remove from encoder directory + $secondary_path = $secondary_dir . basename($path); + if (file_exists($secondary_path)) unlink($secondary_path); + } + } + } + // Handle File Uploads foreach ($upload_paths as $input_name => $destination) { if (isset($_FILES[$input_name]) && $_FILES[$input_name]['error'] == 0) { $tmp_path = $_FILES[$input_name]['tmp_name']; - + // 1. Verify it is actually a PNG using GD/getimagesize $image_info = @getimagesize($tmp_path); if (!$image_info || $image_info[2] !== IMAGETYPE_PNG) { @@ -35,13 +48,8 @@ if (isset($_POST['submit'])) { } // 2. Determine target dimensions - // Logo: 512x512, Ad: 1080x1080 - $target_width = 1080; - $target_height = 1080; - if ($input_name === 'app_logo') { - $target_width = 512; - $target_height = 512; - } + $target_width = ($input_name === 'app_logo') ? 512 : 1080; + $target_height = ($input_name === 'app_logo') ? 512 : 1080; // 3. Load the source image $src_img = @imagecreatefrompng($tmp_path); @@ -50,7 +58,7 @@ if (isset($_POST['submit'])) { continue; } - // 4. Create a blank truecolor canvas for the new size + // 4. Create a blank truecolor canvas $dst_img = imagecreatetruecolor($target_width, $target_height); // 5. Preserve transparency for PNG @@ -59,28 +67,32 @@ if (isset($_POST['submit'])) { $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127); imagefill($dst_img, 0, 0, $transparent); - // 6. Resize (Resample) using interpolation for high quality + // 6. Resize (Resample) imagecopyresampled( - $dst_img, $src_img, - 0, 0, 0, 0, - $target_width, $target_height, - imagesx($src_img), imagesy($src_img) + $dst_img, + $src_img, + 0, + 0, + 0, + 0, + $target_width, + $target_height, + imagesx($src_img), + imagesy($src_img) ); // 7. Save to primary destination with compression (level 7) if (imagepng($dst_img, $destination, 7)) { - // Create a copy in the encoder directory (/var/www/encoder/) - $filename = basename($destination); + $filename = basename($int_name); $secondary_destination = $secondary_dir . $filename; - + if (!copy($destination, $secondary_destination)) { - $errors[] = "Failed to create secondary copy for $input_name in encoder folder."; + $errors[] = "Failed to create secondary copy for $input_name."; } } else { $errors[] = "Failed to save processed $input_name."; } - // 8. Free memory imagedestroy($src_img); imagedestroy($dst_img); } @@ -106,8 +118,6 @@ if (isset($_POST['submit'])) { // Save if no errors occurred if (empty($errors)) { file_put_contents($json_file, json_encode($data_to_save, JSON_PRETTY_PRINT)); - - // Redirect to the same page to refresh the data and clear POST state header("Location: " . $_SERVER['PHP_SELF']); exit; } else { @@ -127,12 +137,23 @@ function getValue($data, $key) return $data[$key] ?? ''; } -// Now we can safely start sending HTML include 'header.php'; ?> -
-
+ + +
+ + + + +

Company Information Entry

@@ -146,54 +167,70 @@ include 'header.php';
- +
- +
- +
- +
- +
- +
- +
- +
+

Upload Ad (PNG)

- - -
Current:
+ + + +
New file selected (will upload on save)
+ +
+ Current:
+ + +
+

Upload Logo (PNG)

- - -
Current:
+ + + +
New file selected (will upload on save)
+ +
+ Current:
+ + +
@@ -202,7 +239,7 @@ include 'header.php';
-
- + +
\ No newline at end of file