#46990 [Opn]: Passing UTF8 strings to filesystem functions produce wrong filenames

From: Date: Fri, 09 Jan 2009 10:54:14 +0000
Subject: #46990 [Opn]: Passing UTF8 strings to filesystem functions produce wrong filenames
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-132684@lists.php.net to get a copy of this message
ID: 46990 User updated by: alex dot bazan at concatel dot com Reported By: alex dot bazan at concatel dot com Status: Open Bug Type: *Directory/Filesystem functions Operating System: win32 only - Windows XP PHP Version: 5.2.8 New Comment: 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 } Previous Comments: ------------------------------------------------------------------------ [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('&#26085;&#26412;&#35486;'); ?> Expected result: ---------------- Directory &#26085;&#26412;&#35486; should be created Actual result: -------------- Directory 日本語 is created ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46990&edit=1

« previous php.bugs (#132684) next »