I have to render a list of files, with link to them. What I have written:
$path = "pdf/".$lang."/*";
$fileList = glob($path);
echo "<ul>";
foreach($fileList as $filename){
$splitted = explode("/", $filename);
echo '<li><a href="'.$filename.'">'.end($splitted).'</a>';
}
echo "</ul>";
It works if there are no special chars in the filenames. If there are, a � is rendered.
I changed the code followings:
$path = "pdf/".$lang."/";
$fileList = glob($path."*");
echo "<ul>";
foreach($fileList as $entry){
$splitted = explode("/", $entry);
$filename = iconv('WINDOWS-1252', 'UTF-8', end($splitted));
echo '<li><a href="'.$path.$filename.'" target="_blank">'.$filename.'</a>';
}
echo "</ul>";
this solution works only on the localhost. Once I publish it the special chars are not rendered correctly. Instead of the ä
it renders ä
.
How can I solve it?
Edit:
This is not a duplicate of this question. As I'written above I get ä not �.
Localhost and server are working on Windows. PHP Version on localhost is 5.6.35. Server in on 7.1.