From 0fddff6c5bf1f216bec23c0240ea9533931dc2e3 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Mon, 16 Mar 2026 21:55:23 -0500 Subject: [PATCH] up --- api/lab/descargar_orden.php | 15 ++++++++++++++- api/lab/upload_orden.php | 13 ++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/api/lab/descargar_orden.php b/api/lab/descargar_orden.php index 851cb4e..afba180 100644 --- a/api/lab/descargar_orden.php +++ b/api/lab/descargar_orden.php @@ -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'); diff --git a/api/lab/upload_orden.php b/api/lab/upload_orden.php index 0209d08..527e4ee 100644 --- a/api/lab/upload_orden.php +++ b/api/lab/upload_orden.php @@ -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;