#35300 [NEW]: PHP cannot read file names with multibyte character encoding
| From: | dmceo415 at yahoo dot com | Date: | Sat, 19 Nov 2005 23:50:49 +0000 |
| Subject: | #35300 [NEW]: PHP cannot read file names with multibyte character encoding | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-88566@lists.php.net to get a copy of this message | ||
From: dmceo415 at yahoo dot com
Operating system: Windows XP
PHP version: 5.0.5
PHP Bug Type: Directory function related
Bug description: PHP cannot read file names with multibyte character encoding
Description:
------------
On an NTFS-formatted drive, Windows XP stores every character of a file
name in two bytes. Specifically, the encoding is UTF-16LE.
PHP's "readdir" has no problem reading NTFS file names that consist only
of characters included in the ISO-8859-1 repertoire. For these characters,
the first UTF-16LE byte is the same as the ISO-8859-1 representation, and
the second byte is simply 0x00, the null byte, which causes no damage.
However, for two-byte characters at higher code points - Chinese
characters, for example - "readdir" fails.
To illustrate, I created a directory with two files. One of the files is
named with Chinese characters; the other is named with ISO-8859-1
compatible characters. The following code:
if ($dir = opendir('.\TestFiles')) {
while (false !== ($file = readdir($dir))) {
echo $file . '<br>';
}
}
produces this output:
.
..
???????.m4a
Greensleeves.m4a
Clearly, "readdir" does not handle the two-byte Chinese characters
correctly. Instead, it returns question marks. This is a big problem if
one wants to use a PHP script to back up an NTFS-formatted drive.
(And, by the way, using mb_internal_encoding("UTF-16LE") does not solve
the problem; this seems to have no impact on "readdir".)
Expected result:
----------------
"readdir" should be able to handle UTF-16 (i.e., two-byte) characters
Actual result:
--------------
"readdir" does not interpret two-byte characters correctly
--
Edit bug report at http://bugs.php.net/?id=35300&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=35300&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=35300&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=35300&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=35300&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=35300&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=35300&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=35300&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=35300&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=35300&r=support
Expected behavior: http://bugs.php.net/fix.php?id=35300&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=35300&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=35300&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=35300&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35300&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=35300&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=35300&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=35300&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=35300&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=35300&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=35300&r=mysqlcfg