multiples documentos
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user