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