Skip to content

Commit

Permalink
Fix: nome file PDF con caratteri speciali
Browse files Browse the repository at this point in the history
  • Loading branch information
trinko committed May 21, 2024
1 parent 5a918e4 commit 91ae4f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/Controller/CoordinatoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,8 @@ public function situazioneAlunnoAction(StaffUtil $staff, PdfManager $pdf, int $a
));
$pdf->createFromHtml($html);
// invia il documento
$nomefile = 'situazione-alunno-'.
strtoupper(str_replace(' ', '-', $alunno->getCognome().'-'.$alunno->getNome())).'.pdf';
return $pdf->send($nomefile);
$nomefile = 'situazione-alunno-'.$alunno->getCognome().'-'.$alunno->getNome();
return $pdf->send($pdf->normalizzaNome($nomefile));
}
// visualizza pagina
return $this->render('coordinatore/situazione_alunno.html.twig', array(
Expand Down
19 changes: 18 additions & 1 deletion src/Util/PdfManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function createFromHtml(string $html) {
*
* @param string $filename Nome del file da inviare al browser
* @param string $mode Modo di invio al browser: I=inline, D=download
*
*
* @return Response Pagina di risposta
*/
public function send(string $filename, string $mode = 'D'): Response {
Expand Down Expand Up @@ -199,4 +199,21 @@ public function convertFormat(string $file): bool {
return false;
}

/**
* Restituisce il nome di file normalizzato in maiuscolo
*
* @param string $nome Nome di file da normalizzare
*
* @return string Nome di file normalizzato
*/
public function normalizzaNome($nome) {
$testo = mb_strtoupper($nome, 'UTF-8');
$testo = str_replace(['À', 'È', 'É', 'Ì', 'Ò', 'Ù'], ['A', 'E', 'E', 'I', 'O', 'U'], $testo);
$testo = preg_replace('/\W+/','-', $testo);
if (substr($testo, -1) == '-') {
$testo = substr($testo, 0, -1);
}
return $testo;
}

}

0 comments on commit 91ae4f3

Please sign in to comment.