Bug #46990 [Asn->Wfx]: Passing UTF8 strings to filesystem functions produce wrong filenames
| From: | felipe@php.net | Date: | Sun, 13 Jun 2010 16:42:53 +0000 |
| Subject: | Bug #46990 [Asn->Wfx]: Passing UTF8 strings to filesystem functions produce wrong filenames | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-151442@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=46990&edit=1
ID: 46990
Updated by: felipe@php.net
Reported by: alex dot bazan at concatel dot com
Summary: Passing UTF8 strings to filesystem functions produce
wrong filenames
-Status: Assigned
+Status: Wont fix
Type: Bug
Package: Filesystem function related
Operating System: win32 only - Windows XP
PHP Version: 6*
Assigned To: pajoye
Previous Comments:
------------------------------------------------------------------------
[2009-01-09 11:24:18] pajoye@php.net
Can't be fixed in 5.2 neither in 5.3. It will work smoothly in 6.x
(unicode support).
------------------------------------------------------------------------
[2009-01-09 10:54:13] alex dot bazan at concatel dot com
For anyone stumbling upon this bug, i wrote a workaround building a
wrapper for filesystem functions. This workaround will will not fix the
issue completely but will work with latin compatible characters when
using UTF8 as the string encoding. People using other characters
(japanese, chinese, hebrew ...) will still have problems.
CODE:
/**
* Wrapper for PHP filesystem functions
*/
class Fsw {
/**
* Returns the filename for use with filesystem functions
*/
static function setName ($file) {
if (DIRECTORY_SEPARATOR=="\\") {
$file=utf8_decode($file);
}
return $file;
}
/**
* Encondes the filename returned by filesystem functions
*/
static function getName ($file) {
if (DIRECTORY_SEPARATOR=="\\") {
$file=utf8_encode($file);
}
return $file;
}
static function file_exists ($filename) {
return file_exists(self::setName($filename));
}
static function fopen ($filename,$mode) {
return fopen(self::setName($filename),$mode);
}
static function opendir ($dirname) {
return opendir(self::setName($dirname));
}
static function readdir ($dir_handle) {
$file=readdir($dir_handle);
if ($file) {
// check if file is found before converting it's
// name or we will convert bool(false) to string
$file=self::getName($file);
}
return $file;
}
// just create any other filesystem function you might use in your code
here
}
------------------------------------------------------------------------
[2009-01-03 13:25:07] jani@php.net
------------------------------------------------------------------------
[2009-01-02 08:06:39] alex dot bazan at concatel dot com
The UTF string did not get saved correctly in the bug report. It was a
japanese string.
------------------------------------------------------------------------
[2009-01-02 08:03:37] alex dot bazan at concatel dot com
Description:
------------
Under Windows, when I use fpoen() or mkdir() with a UTF8 encoded string,
the file or directory name is not converted to the filesystem encoding
and thus the file or directory is created with a wrong file name.
Reproduce code:
---------------
<?php mkdir('日本語'); ?>
Expected result:
----------------
Directory 日本語 should be created
Actual result:
--------------
Directory æ¥æ¬èª is created
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=46990&edit=1