doushang7209 2016-03-27 17:00
浏览 36

PHP DirectoryIterator在Windows上缺少目录

I'm making module to get list of directories in specified path using PHP DirectoryIterator. There is example:

class GardenUtils
{
    public static function getPath()
    {
        return public_path() . "/images/garden/";
    }

    public static function getAlbumDirectories()
    {
        $directories = [];

        $directoryIterator = new DirectoryIterator(self::getPath());

        foreach ($directoryIterator as $directory) {
            if (!$directory->isDot() && $directory->isDir()) {
                $directories[] = FileUtil::normalizeFileName($directory->getFilename());
            }
        }

        return $directories;
    }
}

My problem is a result of scanning in the array are missing some of the directory. For example - 12 are placed in the directory, and fall into the array 10. If i remove $directory->isDir() condition, all files will be scanned. In addition, if i call $directory->getType(), script crashing with RuntimeException. All directories contains Russian letters and diacritics.

Example of name that scanned correctly: Аквилегия (Aquilégia)
Example of name, that cause problems: Хоста (Hósta) (h5-30)

That problem reproduced with PHP 5.6.12 on Windows 7 with Russian locale. PHP 5.5.25 on Linux system works correctly.

How can i solve it?

  • 写回答

0条回答 默认 最新

    报告相同问题?