Fix PHP syntax error in file validation logic
Co-authored-by: naielv <109038805+naielv@users.noreply.github.com>
This commit is contained in:
@@ -153,6 +153,8 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
"created_at" => time()
|
"created_at" => time()
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$can_add_item = true;
|
||||||
|
|
||||||
if ($item_type === "link" && $item_url !== "") {
|
if ($item_type === "link" && $item_url !== "") {
|
||||||
$item["url"] = $item_url;
|
$item["url"] = $item_url;
|
||||||
} elseif ($item_type === "file" && isset($_FILES["item_file"]) && $_FILES["item_file"]["error"] === UPLOAD_ERR_OK) {
|
} elseif ($item_type === "file" && isset($_FILES["item_file"]) && $_FILES["item_file"]["error"] === UPLOAD_ERR_OK) {
|
||||||
@@ -166,19 +168,22 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
$max_size = 500 * 1024 * 1024; // 500MB
|
$max_size = 500 * 1024 * 1024; // 500MB
|
||||||
if ($_FILES["item_file"]["size"] > $max_size) {
|
if ($_FILES["item_file"]["size"] > $max_size) {
|
||||||
$error = "El archivo es demasiado grande. Tamaño máximo: 500MB.";
|
$error = "El archivo es demasiado grande. Tamaño máximo: 500MB.";
|
||||||
continue;
|
$can_add_item = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate file type
|
// Validate file type
|
||||||
|
if ($can_add_item) {
|
||||||
$original_name = $_FILES["item_file"]["name"];
|
$original_name = $_FILES["item_file"]["name"];
|
||||||
$ext = strtolower(pathinfo($original_name, PATHINFO_EXTENSION));
|
$ext = strtolower(pathinfo($original_name, PATHINFO_EXTENSION));
|
||||||
$allowed_extensions = ["pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "jpg", "jpeg", "png", "gif", "webp", "txt", "zip", "mp4", "mp3"];
|
$allowed_extensions = ["pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "jpg", "jpeg", "png", "gif", "webp", "txt", "zip", "mp4", "mp3"];
|
||||||
|
|
||||||
if (!in_array($ext, $allowed_extensions, true)) {
|
if (!in_array($ext, $allowed_extensions, true)) {
|
||||||
$error = "Tipo de archivo no permitido. Extensiones permitidas: " . implode(", ", $allowed_extensions);
|
$error = "Tipo de archivo no permitido. Extensiones permitidas: " . implode(", ", $allowed_extensions);
|
||||||
continue;
|
$can_add_item = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($can_add_item) {
|
||||||
$safe_name = safe_filename($original_name);
|
$safe_name = safe_filename($original_name);
|
||||||
$target_path = "$project_dir/$safe_name";
|
$target_path = "$project_dir/$safe_name";
|
||||||
|
|
||||||
@@ -196,9 +201,12 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
$item["original_name"] = $original_name;
|
$item["original_name"] = $original_name;
|
||||||
} else {
|
} else {
|
||||||
$error = "No se pudo subir el archivo.";
|
$error = "No se pudo subir el archivo.";
|
||||||
|
$can_add_item = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($can_add_item) {
|
||||||
if (!isset($project["items"])) {
|
if (!isset($project["items"])) {
|
||||||
$project["items"] = [];
|
$project["items"] = [];
|
||||||
}
|
}
|
||||||
@@ -212,6 +220,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($action === "delete_item") {
|
if ($action === "delete_item") {
|
||||||
$project_id = $_POST["project_id"] ?? "";
|
$project_id = $_POST["project_id"] ?? "";
|
||||||
|
|||||||
Reference in New Issue
Block a user