added modified type oh pèhoto and resize
This commit is contained in:
+14
-14
@@ -17,8 +17,8 @@ $uploadFeedback = null; // ['type' => 'success'|'error', 'text' => '...']
|
|||||||
/* -------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------
|
||||||
* Upload certificato (POST) con validazione robusta
|
* Upload certificato (POST) con validazione robusta
|
||||||
* ---------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------- */
|
||||||
$allowedExt = ['pdf', 'jpg', 'jpeg', 'png'];
|
$allowedExt = ['pdf', 'jpg', 'jpeg', 'png', 'webp', 'avif'];
|
||||||
$allowedMime = ['application/pdf', 'image/jpeg', 'image/png'];
|
$allowedMime = ['application/pdf', 'image/jpeg', 'image/png', 'image/webp', 'image/avif'];
|
||||||
$maxBytes = 16 * 1024 * 1024; // 16 MB
|
$maxBytes = 16 * 1024 * 1024; // 16 MB
|
||||||
$uploadDir = 'user/document/';
|
$uploadDir = 'user/document/';
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ if (
|
|||||||
$realMime = $finfo->file($file['tmp_name']);
|
$realMime = $finfo->file($file['tmp_name']);
|
||||||
|
|
||||||
if (!in_array($ext, $allowedExt, true) || !in_array($realMime, $allowedMime, true)) {
|
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 {
|
} else {
|
||||||
$safeName = bin2hex(random_bytes(16)) . '.' . $ext;
|
$safeName = bin2hex(random_bytes(16)) . '.' . $ext;
|
||||||
$destination = $uploadDir . $safeName;
|
$destination = $uploadDir . $safeName;
|
||||||
@@ -140,10 +140,7 @@ $documents = $stmtDocs->fetchAll();
|
|||||||
minDate: 0
|
minDate: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
// Punto 3: propone come scadenza oggi + 1 anno (modificabile)
|
|
||||||
if (!$("#expiryDate").val()) {
|
|
||||||
$("#expiryDate").datepicker("setDate", "+1y");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function confirmDeleteCertificate(id) {
|
function confirmDeleteCertificate(id) {
|
||||||
@@ -173,11 +170,13 @@ $documents = $stmtDocs->fetchAll();
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var f = input.files[0];
|
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;
|
var maxBytes = 16 * 1024 * 1024;
|
||||||
|
|
||||||
if (allowed.indexOf(f.type) === -1) {
|
if (allowed.indexOf(f.type) === -1 && allowedExt.indexOf(ext) === -1) {
|
||||||
label.textContent = 'Formato non valido: usa PDF, JPG o PNG';
|
label.textContent = 'Formato non valido: usa PDF, JPG, PNG, WebP o AVIF';
|
||||||
label.style.color = '#dc3545';
|
label.style.color = '#dc3545';
|
||||||
input.value = '';
|
input.value = '';
|
||||||
return;
|
return;
|
||||||
@@ -190,7 +189,8 @@ $documents = $stmtDocs->fetchAll();
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PDF o immagini già leggere: nessuna compressione
|
// 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.textContent = f.name;
|
||||||
label.style.color = '#198754';
|
label.style.color = '#198754';
|
||||||
return;
|
return;
|
||||||
@@ -200,7 +200,7 @@ $documents = $stmtDocs->fetchAll();
|
|||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
|
|
||||||
compressImage(f, 1800, 0.8).then(function(blob) {
|
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 newName = f.name.replace(/\.[^.]+$/, '') + '.jpg';
|
||||||
var newFile = new File([blob], newName, {
|
var newFile = new File([blob], newName, {
|
||||||
type: 'image/jpeg'
|
type: 'image/jpeg'
|
||||||
@@ -488,7 +488,7 @@ $documents = $stmtDocs->fetchAll();
|
|||||||
<div class="card cert-card">
|
<div class="card cert-card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="section-title">Carica un nuovo documento</div>
|
<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">
|
<form method="post" enctype="multipart/form-data">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -515,7 +515,7 @@ $documents = $stmtDocs->fetchAll();
|
|||||||
<span class="file-chosen" id="fileChosenLabel">Nessun file selezionato</span>
|
<span class="file-chosen" id="fileChosenLabel">Nessun file selezionato</span>
|
||||||
</label>
|
</label>
|
||||||
<input type="file" id="fileToUpload" name="fileToUpload" class="d-none"
|
<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>
|
</div>
|
||||||
|
|
||||||
<p class="privacy-note">
|
<p class="privacy-note">
|
||||||
|
|||||||
Reference in New Issue
Block a user