I'm using PHPSpreadsheet to export an html table to .xlsx file. Everything works fine except...
I want to give the filename the greek fullname of the employee that is stored in a SESSION but I'm getting something like this:
2021_ΑΘΑΝΑΣΙΟΣ ΛΑΜΠΡΙΔΗΣ.xlsx
Is there a way I can set the actual name as the file name???
Edit: the code is
if(isset($_POST["file_content"]))
{
$temporary_html_file = './tmp_html/' . time() . '.html';
file_put_contents($temporary_html_file, $_POST["file_content"]);
$reader = IOFactory::createReader('Html');
$spreadsheet = $reader->load($temporary_html_file);
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$filename = $ecoYear . "_" . $_SESSION['fullname'] . '.xlsx';
$writer->save($filename);
header('Content-Type: application/x-www-form-urlencoded');
header('Content-Transfer-Encoding: Binary');
header("Content-disposition: attachment; filename=\"".$filename."\"");
readfile($filename);
unlink($temporary_html_file);
unlink($filename);
exit;
}
html_entity_decode
— Convert HTML entities to their corresponding characters
<?php
$orig = "2021_ΑΘΑΝΑΣΙΟΣ ΛΑΜΠΡΙΔΗΣ.xlsx";
$text = html_entity_decode($orig);
echo $orig . PHP_EOL;
echo $text . PHP_EOL;
?>
Output: 72103715.php
2021_ΑΘΑΝΑΣΙΟΣ ΛΑΜΠΡΙΔΗΣ.xlsx 2021_ΑΘΑΝΑΣΙΟΣ ΛΑΜΠΡΙΔΗΣ.xlsx