34849-vm/save_cobertura_banner.php
2026-02-03 01:43:03 +00:00

46 lines
1.5 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['banner_image'])) {
$target_dir = "assets/uploads/";
$target_file = $target_dir . "cobertura_banner.jpg";
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($_FILES["banner_image"]["name"], PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["banner_image"]["tmp_name"]);
if ($check !== false) {
$uploadOk = 1;
} else {
$_SESSION['error_message'] = "El archivo no es una imagen.";
$uploadOk = 0;
}
// Allow certain file formats
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif") {
$_SESSION['error_message'] = "Solo se permiten archivos JPG, JPEG, PNG y GIF.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["banner_image"]["tmp_name"], $target_file)) {
$_SESSION['success_message'] = "La imagen de cabecera ha sido actualizada.";
} else {
$_SESSION['error_message'] = "Hubo un error al subir tu archivo.";
}
}
} else {
$_SESSION['error_message'] = "No se recibió ningún archivo.";
}
header("Location: configuracion.php");
exit;
?>