php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46990 Passing UTF8 strings to filesystem functions produce wrong filenames
Submitted: 2009-01-02 08:03 UTC Modified: 2010-06-13 18:42 UTC
Votes:39
Avg. Score:4.4 ± 0.9
Reproduced:35 of 35 (100.0%)
Same Version:19 (54.3%)
Same OS:21 (60.0%)
From: alex dot bazan at concatel dot com Assigned: pajoye
Status: Wont fix Package: Filesystem function related
PHP Version: 6* OS: win32 only - Windows XP
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-01-02 08:03 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-02 08:06 UTC] 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-03 13:25 UTC] jani@php.net

 [2009-01-09 10:54 UTC] 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-09 11:24 UTC] pajoye@php.net
Can't be fixed in 5.2 neither in 5.3. It will work smoothly in 6.x (unicode support).
 [2010-06-13 18:42 UTC] felipe@php.net
-Status: Assigned +Status: Wont fix
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Mon Apr 21 04:01:57 2014 UTC