Bug #75063 [Com]: Many filesystem-related functions do not work with multibyte file names
| From: | anrdaemon at freemail dot ru | Date: | Fri, 11 Aug 2017 12:04:35 +0000 |
| Subject: | Bug #75063 [Com]: Many filesystem-related functions do not work with multibyte file names | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-210604@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75063&edit=1
ID: 75063
Comment by: anrdaemon at freemail dot ru
Reported by: anrdaemon at freemail dot ru
Summary: Many filesystem-related functions do not work with
multibyte file names
Status: Feedback
Type: Bug
Package: Filesystem function related
Operating System: Windows
PHP Version: 7.1.8
Block user comment: N
Private report: N
New Comment:
Weird. Works for me if only filename contains multibyte characters, but breaks when path contains
them also, but again, only for multibyte file names.
Can you please try it with parent directory name contaning multibyte characters?
Another interesting finding: getcwd() returns natively encoded filename.
$ php.exe -nf opendir.php
<?php
print file_get_contents(__FILE__) . "-- \n";
print ini_get("internal_encoding") . "\n";
print ini_get("default_charset") . "\n";
print getcwd() . "\n";
print iconv('CP1251', 'UTF-8', getcwd()) . "\n";
foreach(["test", "ÑеÑÑ"] as $fn)
file_put_contents("$fn.txt", "");
if ($dh = opendir(getcwd())) {
while (($file = readdir($dh)) !== false) {
echo "filename: $file : filetype: " . filetype($file) . "\n";
}
closedir($dh);
}
--
UTF-8
C:\dev\temp\
C:\dev\temp\ÑеÑÑ
filename: . : filetype: dir
filename: .. : filetype: dir
filename: opendir.php : filetype: file
filename: test.txt : filetype: file
filename: UTF-8.php : filetype: file
Warning: filetype(): Lstat failed for ÑеÑÑ.txt in
C:\dev\temp\ÑеÑÑ\opendir.php on line 12
filename: ÑеÑÑ.txt : filetype:
Previous Comments:
------------------------------------------------------------------------
[2017-08-11 10:40:15] requinix@php.net
Works for me. Are you sure you saved the file in UTF-8 format?
------------------------------------------------------------------------
[2017-08-11 10:14:29] anrdaemon at freemail dot ru
Description:
------------
Many filesystem functions that read, write or otherwise deal with file names are unable to work with
multibyte encoded filenames, such as when internal_encoding is equal to UTF-8.
Even the example in https://php.net/opendir doesn't work,
if a path contains multibyte sequences.
Test script:
---------------
<?php
print ini_get("internal_encoding") . "\n";
print ini_get("default_charset") . "\n";
foreach(["test", "ÑеÑÑ"] as $fn)
file_put_contents("$fn.txt", "");
print_r(glob("*.txt"));
Expected result:
----------------
$ php -nf ./xx.php
UTF-8
Array
(
[0] => test.txt
[1] => ÑеÑÑ.txt
)
Actual result:
--------------
$ php -nf ./xx.php
UTF-8
Array
(
[0] => test.txt
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75063&edit=1