Correcao limite upload
This commit is contained in:
@@ -4,6 +4,28 @@ $errorMsg = $_SESSION['flash_error'] ?? '';
|
|||||||
if ($hasError) {
|
if ($hasError) {
|
||||||
unset($_SESSION['flash_error']); // Prevent toast from showing
|
unset($_SESSION['flash_error']); // Prevent toast from showing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getBytesFromIni($val) {
|
||||||
|
if (empty($val)) return 0;
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
|
$maxUploadSizeBytes = getBytesFromIni(ini_get('upload_max_filesize'));
|
||||||
|
$maxPostSizeBytes = getBytesFromIni(ini_get('post_max_size'));
|
||||||
|
|
||||||
|
// Fallbacks caso não consiga ler corretamente
|
||||||
|
if ($maxUploadSizeBytes <= 0) $maxUploadSizeBytes = 20 * 1024 * 1024;
|
||||||
|
if ($maxPostSizeBytes <= 0) $maxPostSizeBytes = 20 * 1024 * 1024;
|
||||||
|
|
||||||
|
$maxUploadSizeMB = floor($maxUploadSizeBytes / (1024 * 1024));
|
||||||
?>
|
?>
|
||||||
<div class="max-w-3xl mx-auto bg-white rounded-xl shadow-sm border border-gray-100 p-6" x-data='orderForm(<?= $hasError ? 'true' : 'false' ?>, <?= htmlspecialchars(json_encode($errorMsg), ENT_QUOTES, 'UTF-8') ?>)'>
|
<div class="max-w-3xl mx-auto bg-white rounded-xl shadow-sm border border-gray-100 p-6" x-data='orderForm(<?= $hasError ? 'true' : 'false' ?>, <?= htmlspecialchars(json_encode($errorMsg), ENT_QUOTES, 'UTF-8') ?>)'>
|
||||||
|
|
||||||
@@ -115,7 +137,7 @@ if ($hasError) {
|
|||||||
<label class="block text-sm font-medium text-gray-700 mb-1">
|
<label class="block text-sm font-medium text-gray-700 mb-1">
|
||||||
Anexos <span class="text-gray-400 font-normal">(PDF, imagens, documentos — opcional)</span>
|
Anexos <span class="text-gray-400 font-normal">(PDF, imagens, documentos — opcional)</span>
|
||||||
</label>
|
</label>
|
||||||
<p class="text-xs text-gray-500 mb-2">Arquivos da ordem judicial (decisão, ofícios, etc.). Tipos aceitos: PDF, PNG, JPG, GIF, DOC, DOCX, XLS, XLSX, TXT — máx. 20 MB por arquivo.</p>
|
<p class="text-xs text-gray-500 mb-2">Arquivos da ordem judicial (decisão, ofícios, etc.). Tipos aceitos: PDF, PNG, JPG, GIF, DOC, DOCX, XLS, XLSX, TXT — máx. <?= $maxUploadSizeMB ?> MB por arquivo.</p>
|
||||||
<div x-data="{ attachNames: [] }" class="mt-1">
|
<div x-data="{ attachNames: [] }" class="mt-1">
|
||||||
<label class="flex justify-center px-6 pt-5 pb-6 border-2 border-gray-300 border-dashed rounded-lg cursor-pointer hover:border-primary-500 transition-colors bg-white">
|
<label class="flex justify-center px-6 pt-5 pb-6 border-2 border-gray-300 border-dashed rounded-lg cursor-pointer hover:border-primary-500 transition-colors bg-white">
|
||||||
<div class="space-y-1 text-center w-full">
|
<div class="space-y-1 text-center w-full">
|
||||||
@@ -188,12 +210,13 @@ if ($hasError) {
|
|||||||
|
|
||||||
validateForm(e) {
|
validateForm(e) {
|
||||||
let totalSize = 0;
|
let totalSize = 0;
|
||||||
let maxSize = 20 * 1024 * 1024; // 20 MB
|
let maxSize = <?= $maxUploadSizeBytes ?>;
|
||||||
|
let maxPostSize = <?= $maxPostSizeBytes ?>;
|
||||||
|
|
||||||
let attachments = document.querySelector('input[name=\'attachments[]\']').files;
|
let attachments = document.querySelector('input[name=\'attachments[]\']').files;
|
||||||
for(let i = 0; i < attachments.length; i++) {
|
for(let i = 0; i < attachments.length; i++) {
|
||||||
if (attachments[i].size > maxSize) {
|
if (attachments[i].size > maxSize) {
|
||||||
this.showError('Arquivo Muito Grande', 'O anexo \'' + attachments[i].name + '\' excede o limite permitido de 20 MB.');
|
this.showError('Arquivo Muito Grande', 'O anexo \'' + attachments[i].name + '\' excede o limite permitido de <?= $maxUploadSizeMB ?> MB.');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -205,7 +228,7 @@ if ($hasError) {
|
|||||||
totalSize += csvFile.size;
|
totalSize += csvFile.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalSize > 40 * 1024 * 1024) { // 40 MB limite de segurança frontend
|
if (totalSize > maxPostSize) {
|
||||||
this.showError('Tamanho Total Excedido', 'O tamanho total de todos os arquivos excede o limite de submissão do servidor.');
|
this.showError('Tamanho Total Excedido', 'O tamanho total de todos os arquivos excede o limite de submissão do servidor.');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user