setFlashdata('success', 'Galeria renomeada.'); header('Location: ' . base_url('views/admin/galerias/edit.php?id=' . $id)); exit; } } // Upload images (several at once: images[]) if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['upload'])) { csrf_check(); $files = []; foreach ((array) ($_FILES['images']['name'] ?? []) as $i => $n) { if ($_FILES['images']['error'][$i] === UPLOAD_ERR_NO_FILE) continue; $files[] = ['name' => $n, 'type' => $_FILES['images']['type'][$i], 'tmp_name' => $_FILES['images']['tmp_name'][$i], 'error' => $_FILES['images']['error'][$i], 'size' => $_FILES['images']['size'][$i]]; } $ok = 0; $failed = []; foreach ($files as $file) { if (db_gallery_image_upload($pdo, $id, $file, $why)) $ok++; else $failed[] = $file['name'] . ' (' . $why . ')'; } if ($ok) session()->setFlashdata('success', $ok === 1 ? 'Imagem carregada.' : "$ok imagens carregadas."); if ($failed) session()->setFlashdata($ok ? 'warning' : 'error', 'Não carregadas: ' . implode(', ', $failed) . '.'); if (!$files) session()->setFlashdata('error', 'Escolha pelo menos uma imagem.'); header('Location: ' . base_url('views/admin/galerias/edit.php?id=' . $id)); exit; } // Over post_max_size PHP drops the whole body ($_POST and $_FILES empty), so say so instead of doing nothing. if ($_SERVER['REQUEST_METHOD'] === 'POST' && !$_POST && (int) ($_SERVER['CONTENT_LENGTH'] ?? 0) > 0) { session()->setFlashdata('error', 'O envio é maior do que o servidor aceita (' . ini_get('post_max_size') . ' no total). Carregue menos imagens de cada vez.'); header('Location: ' . base_url('views/admin/galerias/edit.php?id=' . $id)); exit; } // Optimize existing images (resize/compress to the gallery cap) if (isset($_POST['optimize'])) { csrf_check(); $stats = img_optimize_dir(__DIR__ . '/../../../uploads/gallery/' . $id . '/', IMG_MAX_GALLERY); session()->setFlashdata($stats['failed'] ? 'warning' : 'success', img_stats_message($stats)); header('Location: ' . base_url('views/admin/galerias/edit.php?id=' . $id)); exit; } // Delete image // POST + CSRF: um link GET podia ser disparado a partir de outro site. if (isset($_POST['del_img']) && is_numeric($_POST['del_img'])) { csrf_check(); db_gallery_image_delete($pdo, (int) $_POST['del_img'], $id); session()->setFlashdata('success', 'Imagem removida — fica na lixeira 30 dias.'); header('Location: ' . base_url('views/admin/galerias/edit.php?id=' . $id)); exit; } $page_title = 'Gerir Galeria'; include __DIR__ . '/../../../includes/header.php'; ?>
Nenhuma imagem nesta galeria.