|  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
Avg. Score:4.4 ± 0.9
Reproduced:44 of 44 (100.0%)
Same Version:20 (45.5%)
Same OS:24 (54.5%)
From: alex dot bazan at concatel dot com Assigned: pajoye (profile)
Status: Wont fix Package: Filesystem function related
PHP Version: 6* OS: win32 only - Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: alex dot bazan at concatel dot com
New email:
PHP Version: OS:


 [2009-01-02 08:03 UTC] alex dot bazan at concatel dot com
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


Add a Patch

Pull Requests

Add a Pull Request


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]

 [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.


 * Wrapper for PHP filesystem functions
class Fsw {

     * Returns the filename for use with filesystem functions
    static function setName ($file) {
        if (DIRECTORY_SEPARATOR=="\\") {
        return $file;

     * Encondes the filename returned by filesystem functions
    static function getName ($file) {
        if (DIRECTORY_SEPARATOR=="\\") {
        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) {
        if ($file) {
            // check if file is found before converting it's
            // name or we will convert bool(false) to string
        return $file;

// just create any other filesystem function you might use in your code here

 [2009-01-09 11:24 UTC]
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]
-Status: Assigned +Status: Wont fix
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 15:01:29 2024 UTC