Accentuating files in directory reading

3

I created a simple directory reading in PHP, but when I upload files with accents, they appear with strange characters and then I can not open those files.

How to correctly read the accent?

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();
?>
    
asked by anonymous 13.05.2014 / 22:15

1 answer

2

There are a few ways to fix it. The one I recommend the most is renomear os arquivos with a hash in sha1 or take accents at the time of inclusion. This will resolve issues with accents and special characters.

Another way to convert these characters you cited is by using utf8_decode(); or utf8_encode();

What do they do?

  

utf8_encode - Encodes an ISO-8859-1 string for UTF-8

     

utf8_decode - Converts a string with ISO-8859-1 characters   encoded with UTF-8 for single-byte ISO-8859-1.

    
14.05.2014 / 07:38