alert('Contact details updated successfully!'); window.location.href='header-changes.php';";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
}
// Handle Logo Upload
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['update_logo'])) {
$targetDir = "assets/img/logo/";
if (!file_exists($targetDir)) {
mkdir($targetDir, 0777, true); // Create directory if not exists
}
if (!isset($_FILES["logo"]) || $_FILES["logo"]["error"] !== UPLOAD_ERR_OK) {
die("");
}
$fileName = basename($_FILES["logo"]["name"]);
$targetFile = $targetDir . $fileName;
$imageFileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));
// Allowed file formats
$allowedFormats = ["jpg", "jpeg", "png", "gif"];
if (!in_array($imageFileType, $allowedFormats)) {
die("");
}
// Check if the file is a real image
$check = getimagesize($_FILES["logo"]["tmp_name"]);
if ($check === false) {
die("");
}
// Move the uploaded file to the destination folder
if (move_uploaded_file($_FILES["logo"]["tmp_name"], $targetFile)) {
// Update logo path in database
$updateQuery = "UPDATE contact_info SET logo = '$targetFile' WHERE id = 1";
if (mysqli_query($conn, $updateQuery)) {
echo "";
} else {
echo "";
}
} else {
echo "";
}
}
?>