Compila o aggiorna le informazioni del tuo profilo.
Carica il tuo certificato medico o altri documenti (PDF, JPG o PNG, max 8 MB).
getConnection(); $iduserlogin = (int) $iduserlogin; function e($value): string { return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); } $message = isset($_GET['message']) ? $_GET['message'] : ''; $uploadFeedback = null; // ['type' => 'success'|'error', 'text' => '...'] /* ------------------------------------------------------------------------- * Gestione upload certificato (POST) — con validazione robusta * ---------------------------------------------------------------------- */ $allowedExt = ['pdf', 'jpg', 'jpeg', 'png']; $allowedMime = ['application/pdf', 'image/jpeg', 'image/png']; $maxBytes = 8 * 1024 * 1024; // 8 MB $uploadDir = 'user/document/'; if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['fileToUpload']) && $_FILES['fileToUpload']['error'] === UPLOAD_ERR_OK ) { $file = $_FILES['fileToUpload']; $documentDescription = trim($_POST['documentDescription'] ?? ''); $expiryDate = trim($_POST['expiryDate'] ?? ''); // 1) Dimensione if ($file['size'] > $maxBytes) { $uploadFeedback = ['type' => 'error', 'text' => 'Il file supera la dimensione massima di 8 MB.']; } else { // 2) Estensione $ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); // 3) Tipo MIME reale (non ci fidiamo dell'estensione dichiarata) $finfo = new finfo(FILEINFO_MIME_TYPE); $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.']; } else { // 4) Nome file sicuro generato dal server (niente input utente nel percorso) $safeName = bin2hex(random_bytes(16)) . '.' . $ext; $destination = $uploadDir . $safeName; if (!is_dir($uploadDir)) { @mkdir($uploadDir, 0755, true); } if (move_uploaded_file($file['tmp_name'], $destination)) { // 5) INSERT con prepared statement $sql = "INSERT INTO certificateuserprofile (iduser, documentdescription, filenamedocument, expirydatedocument) VALUES (:iduser, :descr, :fname, :expiry)"; $stmt = $pdo->prepare($sql); $ok = $stmt->execute([ ':iduser' => $iduserlogin, ':descr' => $documentDescription, ':fname' => $safeName, ':expiry' => $expiryDate !== '' ? $expiryDate : null, ]); $uploadFeedback = $ok ? ['type' => 'success', 'text' => 'Documento caricato correttamente.'] : ['type' => 'error', 'text' => 'Errore nel salvataggio del documento. Riprova.']; } else { $uploadFeedback = ['type' => 'error', 'text' => 'Caricamento del file non riuscito. Riprova.']; } } } } elseif ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['fileToUpload']) && $_FILES['fileToUpload']['error'] !== UPLOAD_ERR_NO_FILE ) { // Un file è stato scelto ma l'upload è fallito lato PHP $uploadFeedback = ['type' => 'error', 'text' => 'Si è verificato un problema durante il caricamento. Riprova.']; } /* ------------------------------------------------------------------------- * Dati profilo utente * ---------------------------------------------------------------------- */ $idprofile = null; $datebirthFromDatabase = ''; $yogaforFromDatabase = ''; $healthissueFromDatabase = ''; $generalcommentFromDatabase = ''; $stmtProfile = $pdo->prepare("SELECT * FROM userprofile WHERE iduser = :iduser LIMIT 1"); $stmtProfile->execute([':iduser' => $iduserlogin]); $rowdata = $stmtProfile->fetch(); if ($rowdata) { $idprofile = $rowdata['iduserprofile']; $datebirthFromDatabase = $rowdata['datebirth'] ?? ''; $yogaforFromDatabase = $rowdata['yogafor'] ?? ''; $healthissueFromDatabase = $rowdata['healthissue'] ?? ''; $generalcommentFromDatabase = $rowdata['generalcomment'] ?? ''; } $isUpdate = !empty($idprofile); $currentYear = date('Y'); ?>
Compila o aggiorna le informazioni del tuo profilo.
Carica il tuo certificato medico o altri documenti (PDF, JPG o PNG, max 8 MB).