diff --git a/encoder/app.php b/encoder/app.php index 7941751..6e77b00 100644 --- a/encoder/app.php +++ b/encoder/app.php @@ -1,4 +1,18 @@ '/var/www/html/app_ad.png', @@ -7,21 +21,21 @@ if (isset($_POST['submit'])) { $errors = []; + // Handle File Uploads foreach ($upload_paths as $input_name => $destination) { if (isset($_FILES[$input_name]) && $_FILES[$input_name]['error'] == 0) { $ext = pathinfo($_FILES[$input_name]['name'], PATHINFO_EXTENSION); if (strtolower($ext) !== 'png') { $errors[] = "File for $input_name must be a PNG."; } else { - if (move_uploaded_file($_FILES[$input_name]['tmp_name'], $destination)) { - // Success - } else { + if (!move_uploaded_file($_FILES[$input_name]['tmp_name'], $destination)) { $errors[] = "Failed to upload $input_name."; } } } } + // Handle Text Fields $text_fields = [ 'channel_name', 'office_address', @@ -38,26 +52,21 @@ if (isset($_POST['submit'])) { $data_to_save[$field] = $_POST[$field] ?? ''; } - if (empty($errors)) + // 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 { + // If there are errors, we continue to the display part so the user can see them + $error_message = implode("
", $errors); + } } -?> - -
+
-

Company Information Entry

+

Company Information Entry

+ + +
+ +
+
- +
- +
- +
- +
- +
- +
@@ -110,7 +125,6 @@ function getValue($data, $key)
-

Upload Ad (PNG)

@@ -121,7 +135,6 @@ function getValue($data, $key)
-

Upload Logo (PNG)