From 275dc5755fb09d265bf93217f332b3541845018b Mon Sep 17 00:00:00 2001 From: solocla Date: Wed, 7 Oct 2026 14:43:56 +0200 Subject: [PATCH] =?UTF-8?q?added=20modified=20type=20oh=20p=C3=A8hoto=20an?= =?UTF-8?q?d=20resize?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/userprofiledoc.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/public/userprofiledoc.php b/public/userprofiledoc.php index b5b1275..5ac09db 100644 --- a/public/userprofiledoc.php +++ b/public/userprofiledoc.php @@ -17,8 +17,8 @@ $uploadFeedback = null; // ['type' => 'success'|'error', 'text' => '...'] /* ------------------------------------------------------------------------- * Upload certificato (POST) con validazione robusta * ---------------------------------------------------------------------- */ -$allowedExt = ['pdf', 'jpg', 'jpeg', 'png']; -$allowedMime = ['application/pdf', 'image/jpeg', 'image/png']; +$allowedExt = ['pdf', 'jpg', 'jpeg', 'png', 'webp', 'avif']; +$allowedMime = ['application/pdf', 'image/jpeg', 'image/png', 'image/webp', 'image/avif']; $maxBytes = 16 * 1024 * 1024; // 16 MB $uploadDir = 'user/document/'; @@ -49,7 +49,7 @@ if ( $realMime = $finfo->file($file['tmp_name']); if (!in_array($ext, $allowedExt, true) || !in_array($realMime, $allowedMime, true)) { - $uploadFeedback = ['type' => 'error', 'text' => 'Formato non consentito. Carica un PDF, JPG o PNG.']; + $uploadFeedback = ['type' => 'error', 'text' => 'Formato non consentito. Carica un PDF, JPG, PNG, WebP o AVIF.']; } else { $safeName = bin2hex(random_bytes(16)) . '.' . $ext; $destination = $uploadDir . $safeName; @@ -140,10 +140,7 @@ $documents = $stmtDocs->fetchAll(); minDate: 0 }); - // Punto 3: propone come scadenza oggi + 1 anno (modificabile) - if (!$("#expiryDate").val()) { - $("#expiryDate").datepicker("setDate", "+1y"); - } + }); function confirmDeleteCertificate(id) { @@ -173,11 +170,13 @@ $documents = $stmtDocs->fetchAll(); return; } var f = input.files[0]; - var allowed = ['application/pdf', 'image/jpeg', 'image/png']; + var allowed = ['application/pdf', 'image/jpeg', 'image/png', 'image/webp', 'image/avif']; + var allowedExt = ['pdf', 'jpg', 'jpeg', 'png', 'webp', 'avif']; + var ext = f.name.split('.').pop().toLowerCase(); var maxBytes = 16 * 1024 * 1024; - if (allowed.indexOf(f.type) === -1) { - label.textContent = 'Formato non valido: usa PDF, JPG o PNG'; + if (allowed.indexOf(f.type) === -1 && allowedExt.indexOf(ext) === -1) { + label.textContent = 'Formato non valido: usa PDF, JPG, PNG, WebP o AVIF'; label.style.color = '#dc3545'; input.value = ''; return; @@ -190,7 +189,8 @@ $documents = $stmtDocs->fetchAll(); } // PDF o immagini giĆ  leggere: nessuna compressione - if (f.type === 'application/pdf' || f.size < 800 * 1024) { + var mustConvert = (ext === 'webp' || ext === 'avif'); + if (f.type === 'application/pdf' || ext === 'pdf' || (!mustConvert && f.size < 800 * 1024)) { label.textContent = f.name; label.style.color = '#198754'; return; @@ -200,7 +200,7 @@ $documents = $stmtDocs->fetchAll(); btn.disabled = true; compressImage(f, 1800, 0.8).then(function(blob) { - if (blob.size >= f.size) throw new Error('nessun guadagno'); + if (!mustConvert && blob.size >= f.size) throw new Error('nessun guadagno'); var newName = f.name.replace(/\.[^.]+$/, '') + '.jpg'; var newFile = new File([blob], newName, { type: 'image/jpeg' @@ -488,7 +488,7 @@ $documents = $stmtDocs->fetchAll();
Carica un nuovo documento
-

Formati accettati: PDF, JPG o PNG (max 16 MB).

+

Formati accettati: PDF, JPG, PNG, WebP o AVIF (max 16 MB).

@@ -515,7 +515,7 @@ $documents = $stmtDocs->fetchAll(); Nessun file selezionato + accept=".pdf,.jpg,.jpeg,.png,.webp,.avif" onchange="handleFileChange(this)" required>