|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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('日本語'); ?>
Expected result:
----------------
Directory 日本語 should be created
Actual result:
--------------
Directory 日本語 is created
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 23:00:01 2025 UTC |
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 }