Bug #74958 [Opn->Fbk]: ScanDir Have Problem with UTF8 Character in Linux

From: Date: Sat, 07 Mar 2020 10:26:24 +0000
Subject: Bug #74958 [Opn->Fbk]: ScanDir Have Problem with UTF8 Character in Linux
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225936@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74958&edit=1

 ID:                 74958
 Updated by:         cmb@php.net
 Reported by:        global dot ninety at gmail dot com
 Summary:            ScanDir Have Problem with UTF8 Character in Linux
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            *General Issues
 Operating System:   Linux
 PHP Version:        7.1.7
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Please provide the information requested by pollita above.


Previous Comments:
------------------------------------------------------------------------
[2017-07-23 21:32:13] pollita@php.net

To help diagnose what's happening here, could you provide the output of this loop where you are
currently using print_r() to produce what's in the image?

foreach (scandir($dir) as $file) {
  var_dump(urlencode($file));
}

Basically, the urlencode() will help us make sense to what *is* showing up in the filename instead
of what you expect.

------------------------------------------------------------------------
[2017-07-20 21:03:58] global dot ninety at gmail dot com

Description:
------------
scandir Have Problem with UTF8 Character

Please check this image:
http://i.imgur.com/3K2Y9YZ.jpg

my folders and files name is UTF8 character (Farsi).

i need scan directorys for get list files with ScanDir , but this function have problem with UTF8
name.

Tested Information: (i have linux host in HostUpon)
System: Linux cs11.uhcloud.com 2.6.32-673.8.1.lve1.4.3.el6.x86_64 #1 SMP Wed Feb 10 08:57:30 EST
2016 x86_64 
PHP Version: 7.1.7

Test script:
---------------
$files = scanDirectories('files');
print_r($files);

public static function scanDirectories($rootDir, $allData=array()) {
        $invisibleFileNames = array(".", "..");
        $dirContent = scandir($rootDir);
        foreach($dirContent as $key => $content) {
            $path = $rootDir.'/'.$content;
            if(!in_array($content, $invisibleFileNames)) {
                if(Self::isFile($path)) {
                    $allData[] = $path;
                }elseif(Self::isDir($path)) {
                    $allData = Self::scanDirectories($path, $allData);
                }
            }
        }
        return $allData;
    }

    public static function isDir($path)
    {
        $result = pathinfo($path);
        if (!array_key_exists("extension",$result))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public static function isFile($path)
    {
        $result = pathinfo($path);
        if (array_key_exists("extension",$result))
        {
            return true;
        }
        else
        {
            return false;
        }
    }



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74958&edit=1


Thread (4 messages)

« previous php.bugs (#225936) next »