3
I created a simple reading of directories in PHP, but when I send files with accentuation, they appear with strange characters and then I cannot open these files.
How to read the accent correctly?
I’ve tried a lot of things changing to UTF8 in HTML, but so far nothing.
<?php
//diretorio
$base = 'files/';
$abreDir = ($_GET['dir'] != '' ? $_GET['dir'] : $base);
$openDir = dir($abreDir);
//voltar
$strrdir = strrpos(substr($abreDir,0,-1),'/');
$voltar = substr($abreDir,0,$strrdir+1);
$openDir = dir($abreDir);
while($arq = $openDir -> read()):
if($arq != '.' && $arq != '..'):
if(is_dir($abreDir.$arq)):
//pastas
echo'<li class="folders"><a href="discovirtual?dir='.$abreDir.$arq.'/">'.$arq.'</a></li>';
else:
//arquivos
echo'<li class="files"><a href="'.$abreDir.$arq.'">'.$arq.'</a></li>';
endif;
endif;
endwhile;
if($abreDir != $base):
echo '<a href="discovirtual?dir='. $voltar.'">Voltar</a>';
endif;
$openDir -> close();
?>
Is it the listing or the time you click on the link to open a file? In the latter case, the file is being server directly by your webserver (apache?), and you need to configure the default encoding to serve each file type. Even so it may not help, since there may be on disk files of the same type with different encodings...
– bfavaretto
First of all, thank you for answering. When I rename it with accentuation, it passes the file to be opened with accentuation in the browser, so I cannot view the file. And when I send the file accentuated to the server, at the time I see in my listing it displays me with strange characters like triangles and etc... Friends I don’t know how to insert the decodes... as I would put utf8_decode in the variable, has any hint... Thanks
– Helio