Accentuation in the directory

Asked

Viewed 293 times

1

I have a directory location problem when it involves an accentuated file or folder. Follow the section below where I try to capture the file size:

$filepath = "$novocaminho".utf8_encode($arquivo);
$tamanho = filesize("$filepath");

In this case it is returning the following error: Warning: filesize(): stat failed for

In another case, where I check if it is a directory, when the directory is without accentuation, the if returns true if it is an accentuated directory it returns false.

if(is_dir(utf8_encode($novocaminho_implode)) == TRUE){

Past directories are of the type string.

I have tried using utf8_encode().

  • utf8_encode() may not be the best option

2 answers

1


One suggestion is to convert everything enters in the database (even rename the file name) in html entities, as follows the php code:

$email = addslashes(htmlentities($_POST['email'], ENT_QUOTES,'UTF-8')); 

This way, all the special characters are converted, and when displaying them, the browser itself will interpret it.


It will be converted according to the table available in http://erikasarti.net/html/acentuacao-caracteres-especiais/

á = á (&aacute)

ã = ã (&atilde)

and so on

  • I tried and it didn’t work. When I check if it is a directory, it returns as false even the string is already in utf-8.

  • Changed the file name to the corresponding characters?

  • Yes, it still hasn’t been.

  • @Jonathandetoni And the $novocaminho? How is he?

  • It’s a string too, in case I store navigation using array, so I can store, build and destroy the path the user is going through. The $newpath is assigned a string returned from the implode function().

0

I found that the problem may be in another point of the code:

if(isset($novocaminho)){
    if(is_dir($novocaminho) == TRUE){

         $diretorio = dir(utf8_encode($novocaminho_implode));

         while (($arquivo = $diretorio->read()) !== false){

When my string, already changed with the UTF-8, is verified by if(is_dir()) it returns false, but only returns false when the string comes with seats, otherwise it continues and traverses the entire directory normally.

Would it be the case to change all my directory to run out of seats? , but I have to show the user the seats. How would I do if I am showing "printing" on the screen exactly the name of the files and folders that are in my directory.

There are other ways to show the directory?

I pass the folder by a string $pastaraiz = "public/data/downloads";. 'Cause if I use the $_SERVER['DOCUMENT_ROOT']; will pass my current folder.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.