H
H
Hazrat Hajikerimov2014-10-11 16:36:38
PHP
Hazrat Hajikerimov, 2014-10-11 16:36:38

PHP opendir() not displaying Cyrillic folders?

The task is to develop a file manager, started.
The first thing I encountered was that opendir does not display folders in Russian, and accordingly does not go to them.
Here is the code, in the documents directory is the "New Folder" folder. It displays it like this:
26e2e77282974f858ee142ef12b649dd.png
Here is the code

self::$path = $_SERVER['DOCUMENT_ROOT'].'/public/cloud/documents/';

        $dir = scandir(self::$path);
        $files = array(
            'dir'  => array(),
            'file' => array()
        );

        foreach($dir as $el){

            if(is_dir(self::$path.$el)){
                $files['dir'][] = $el;
            }else{
                $files['file'][] = $el;
            }
        }

Used iconv:
iconv('utf-8','Windows-1252',$_SERVER['DOCUMENT_ROOT'].'/public/cloud/documents/');

In general, I looked for information, they explained it to me easier to translate into transliteration. But this is inconvenient, tell me how to act in this situation.
The script is spinning on win 8 (open server) but upon completion of course CentOS
Upd.
The crux of the matter is that opendir does not open folders with Russian letters! How to solve it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
m0rd, 2014-10-11
@m0rd

Well, the Russian encoding is only not 1252, but 1251, as far as I remember

A
Alexander Taratin, 2014-10-11
@Taraflex

Are meta-charset explicitly specified in the page code? It won't work in webkits otherwise / won't always work.

K
khomaldi, 2019-01-02
@khomaldi

I understand that the question was asked more than three years ago, but there is still no answer.
You have an error in the iconv function, you need to swap the encodings.
False: Correct : iconv('utf-8', 'Windows-1252', string)
iconv('Windows-1251', 'UTF-8', string)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question