The problem with Cyrillic. There is a file-picture "photo.jpg". If we write this:

<img src="фото/jpg" /> 

then everything works, and if through a script

 $file = scandir($dir); echo "<img src='" . $file[2] . "' />"; 

it fails because php encodes the file name into something like F% BF% BD% EF% BF% BD% EF and prints not found . This is probably a banal problem, but probably I do not have enough brain substance to solve it.

  • These are file system encoding features. - istem

3 answers 3

This bug, which manifests itself in different guises, is fixed in PHP 7.1. See here https://ru.stackoverflow.com/a/591374/227924 as well as in the English version. In PHP versions prior to 7.1, the single-byte Windows API is used, and it is hard to fight this or not at all. Probably most of the questions on file name encoding can be labeled as duplicates.

Thanks.

    try re-encoding the file name to utf-8 or cp1251 via iconv http://www.php.net/manual/ru/function.iconv.php

    • iconv ("cp1251", "utf-8") - then pkhp ceases to see Latin characters, in my opinion. - Deus
    • @iamsalnikov, thank you once again stumbled your nose. I tried to use this function before, but apparently something went wrong. I tried again - everything is OK! Thank! - Deus

    and what is your encoding? Try at the beginning of the script: ini_set('default_charset','UTF-8');

    Or like this: http://php.net/manual/en/function.utf8-encode.php

    • @markgenuine, ini_set sets the coding of pages, not files. Everything is OK, iconv helped - Deus
    • oh exactly what che tupanul probably sleepy: -D - markgenuine 8:08 pm