added modified type oh pèhoto and resize

This commit is contained in:
2026-10-07 14:43:56 +02:00
parent dec2fdf60e
commit 275dc5755f
+14 -14
View File
@@ -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();
<div class="card cert-card">
<div class="card-body">
<div class="section-title">Carica un nuovo documento</div>
<p class="section-lead">Formati accettati: PDF, JPG o PNG (max 16 MB).</p>
<p class="section-lead">Formati accettati: PDF, JPG, PNG, WebP o AVIF (max 16 MB).</p>
<form method="post" enctype="multipart/form-data">
<div class="row">
@@ -515,7 +515,7 @@ $documents = $stmtDocs->fetchAll();
<span class="file-chosen" id="fileChosenLabel">Nessun file selezionato</span>
</label>
<input type="file" id="fileToUpload" name="fileToUpload" class="d-none"
accept=".pdf,.jpg,.jpeg,.png" onchange="handleFileChange(this)" required>
accept=".pdf,.jpg,.jpeg,.png,.webp,.avif" onchange="handleFileChange(this)" required>
</div>
<p class="privacy-note">