'/var/www/html/app_ad.png',
'app_ad' => '/var/www/html/app_ad.png',
'app_logo' => '/var/www/html/app_logo.png'
];
$secondary_dir = '/var/www/encoder/';
$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 {
// Move to primary destination (/var/www/html/)
if (move_uploaded_file($_FILES[$input_name]['tmp_name'], $destination)) {
// Create a copy in the encoder directory (/var/www/encoder/)
$filename = basename($destination);
$secondary_destination = $secondary_dir . $filename;
if (!copy($destination, $secondary_destination)) {
$errors[] = "Failed to create secondary copy for $input_name in encoder folder.";
}
} else {
$errors[] = "Failed to upload $input_name.";
}
}
}
}
// Handle Text Fields
$text_fields = [
'channel_name',
'office_address',
'contact_details',
'enforcement_officer',
'eo_contact_details',
'company_name',
'cin_number',
'gstin_number'
];
$data_to_save = [];
foreach ($text_fields as $field) {
$data_to_save[$field] = $_POST[$field] ?? '';
}
// 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("cap_url: " . $_SERVER['PHP_SELF']);
header("Location: " . $_SERVER['PHP_SELF']);
exit;
} else {
$error_message = implode("
", $errors);
}
}
// --- 2. Load Data for Display ---
$saved_data = [];
if (file_exists($json_file)) {
$json_content = file_get_contents($json_file);
$saved_data = json_decode($json_content, true) ?? [];
}
function getValue($data, $key)
{
return $data[$key] ?? '';
}
// Now we can safely start sending HTML
include 'header.php';
?>