multiples documentos

This commit is contained in:
Lizandro Guarnizo
2026-04-08 09:58:08 -05:00
parent db254ca02f
commit 882ce56e96
4 changed files with 216 additions and 70 deletions
+19
View File
@@ -117,9 +117,28 @@ function _extraerCampos(array $datos, string $tipo): array {
$cuerpo = isset($datos['cuerpo'])
? strip_tags((string)$datos['cuerpo'], ALLOWED_HTML_TAGS)
: null;
// Validar y limpiar archivos (array de {nombre,path,mime,size})
$archivos = null;
if (!empty($datos['archivos']) && is_array($datos['archivos'])) {
$limpios = [];
foreach ($datos['archivos'] as $a) {
$path = preg_replace('/[^a-zA-Z0-9._\-]/', '', (string)($a['path'] ?? ''));
if (!$path) continue;
$limpios[] = [
'nombre' => mb_substr(strip_tags((string)($a['nombre'] ?? $path)), 0, 100),
'path' => $path,
'mime' => preg_replace('/[^a-zA-Z0-9\/\-+.]/', '', (string)($a['mime'] ?? '')),
'size' => (int)($a['size'] ?? 0),
];
}
if ($limpios) $archivos = json_encode($limpios, JSON_UNESCAPED_UNICODE);
}
return array_filter([
'titulo' => isset($datos['titulo']) ? mb_substr(trim($datos['titulo']), 0, 200) : null,
'cuerpo' => $cuerpo ?: null,
'imagen_path' => isset($datos['imagen_path']) ? preg_replace('/[^a-zA-Z0-9._\-]/', '', (string)$datos['imagen_path']) : null,
'archivos' => $archivos,
], fn($v) => $v !== null);
}