add upload anexos pos ordem criada

This commit is contained in:
HalbeBruno
2026-03-18 13:58:20 -03:00
parent b4799a1d42
commit d709d4cb09
5 changed files with 86 additions and 9 deletions

View File

@@ -22,8 +22,23 @@ class AttachmentService
'text/plain' => 'txt',
];
/** Tamanho máximo por arquivo: 20 MB */
private const MAX_SIZE = 20 * 1024 * 1024;
/**
* Retorna o tamanho máximo de upload, lendo do PHP ini.
*/
private function getMaxSize(): int
{
$val = ini_get('upload_max_filesize');
if (empty($val)) return 20 * 1024 * 1024;
$val = trim($val);
$last = strtolower($val[strlen($val)-1]);
$val = (int)$val;
switch($last) {
case 'g': $val *= 1024;
case 'm': $val *= 1024;
case 'k': $val *= 1024;
}
return $val > 0 ? $val : 20 * 1024 * 1024;
}
/**
* Raiz do diretório de uploads (fora do public/).
@@ -81,8 +96,10 @@ class AttachmentService
throw new \Exception("Erro no upload do arquivo '{$file['name']}': código {$file['error']}");
}
if ($file['size'] > self::MAX_SIZE) {
throw new \Exception("O arquivo '{$file['name']}' excede o tamanho máximo permitido de 20 MB.");
$maxSize = $this->getMaxSize();
if ($file['size'] > $maxSize) {
$maxSizeMB = floor($maxSize / (1024 * 1024));
throw new \Exception("O arquivo '{$file['name']}' excede o tamanho máximo permitido de {$maxSizeMB} MB.");
}
// Detecta o tipo MIME real do arquivo (não confiar só no header HTTP)

View File

@@ -36,7 +36,10 @@ class OrderProcessor
$domains = array_unique($domains); // Remove duplicates in batch
$conn->beginTransaction();
$inTransaction = $conn->inTransaction();
if (!$inTransaction) {
$conn->beginTransaction();
}
try {
$stmtCheck = $conn->prepare("SELECT id FROM domains WHERE name = :name");
@@ -77,11 +80,15 @@ class OrderProcessor
]);
}
$conn->commit();
if (!$inTransaction) {
$conn->commit();
}
return count($domains);
} catch (\Exception $e) {
$conn->rollBack();
if (!$inTransaction) {
$conn->rollBack();
}
throw $e;
}
}