This commit is contained in:
Lizandro Guarnizo
2026-03-16 21:55:23 -05:00
parent 4106840a39
commit 0fddff6c5b
2 changed files with 26 additions and 2 deletions
+14 -1
View File
@@ -58,8 +58,21 @@ if (!$mime || $mime === 'application/octet-stream') {
$inlineTypes = ['application/pdf', 'image/jpeg', 'image/png', 'image/gif', 'image/webp'];
$disposition = in_array($mime, $inlineTypes) ? 'inline' : 'attachment';
// Si el archivo fue guardado con extensión .bin, usar la correcta según MIME
$mimeToExt = [
'application/pdf' => 'pdf',
'application/msword' => 'doc',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
'image/jpeg' => 'jpg',
'image/png' => 'png',
'image/gif' => 'gif',
'image/webp' => 'webp',
];
$downloadExt = ($ext === 'bin' && isset($mimeToExt[$mime])) ? $mimeToExt[$mime] : $ext;
$downloadName = substr($filename, 0, strrpos($filename, '.') + 1) . $downloadExt;
header('Content-Type: ' . $mime);
header('Content-Disposition: ' . $disposition . '; filename="' . rawurlencode($filename) . '"');
header('Content-Disposition: ' . $disposition . '; filename="' . rawurlencode($downloadName) . '"');
header('Content-Length: ' . filesize($path));
header('Cache-Control: private, max-age=3600');
header('X-Content-Type-Options: nosniff');
+12 -1
View File
@@ -56,7 +56,18 @@ if (!in_array($mime, $allowedMimes, true)) {
// Generar nombre único y seguro
$origExt = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
$origExt = preg_replace('/[^a-z0-9]/', '', $origExt);
if (!$origExt) $origExt = 'bin';
if (!$origExt) {
$mimeToExt = [
'image/jpeg' => 'jpg',
'image/png' => 'png',
'image/gif' => 'gif',
'image/webp' => 'webp',
'application/pdf' => 'pdf',
'application/msword' => 'doc',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
];
$origExt = $mimeToExt[$mime] ?? 'bin';
}
$newName = 'orden_' . date('Ymd_His') . '_' . bin2hex(random_bytes(4)) . '.' . $origExt;