private function getFiles(string $dir, bool $recursive = false, $limit = null): array
    {
        if ($limit === 0) {
            return [];
        }
        $result = [];
        if (is_dir($dir)) {
            $list = scandir($dir);
            if (is_array($list)) {
                foreach ($list as $filename) {
                    if ($filename != '.' && $filename != '..') {
                        if (is_dir($dir . $filename)) {
                            if ($recursive === true) {
                                $dirResult = $this->getFiles($dir . $filename . '/', true, $limit !== null ? ($limit - sizeof($result)) : null);
                                if (!empty($dirResult)) {
                                    foreach ($dirResult as $index => $value) {
                                        $dirResult[$index] = $filename . '/' . $value;
                                    }
                                    $result = array_merge($result, $dirResult);
                                }
                            }
                        } else {
                            $result[] = $filename;
                            if ($limit !== null && $limit === sizeof($result)) {
                                break;
                            }
                        }
                    }
                }
            }
        }
        return $result;
    }
private function getFiles(string $dir, bool $recursive = false, $limit = null): array
    {
        if ($limit === 0) {
            return [];
        }
        $result = [];
        if (is_dir($dir)) {
            $list = scandir($dir);
            if (is_array($list)) {
                foreach ($list as $filename) {
                    if ($filename != '.' && $filename != '..') {
                        if (is_dir($dir . $filename)) {
                            if ($recursive === true) {
                                $dirResult = $this->getFiles($dir . $filename . '/', true, $limit !== null ? ($limit - sizeof($result)) : null);
                                if (!empty($dirResult)) {
                                    foreach ($dirResult as $index => $value) {
                                        $dirResult[$index] = $filename . '/' . $value;
                                    }
                                    $result = array_merge($result, $dirResult);
                                }
                            }
                        } else {
                            $result[] = $filename;
                            if ($limit !== null && $limit === sizeof($result)) {
                                break;
                            }
                        }
                    }
                }
            }
        }
        return $result;
    }
private function getFiles ( string $ dir , bool $ recursive = false , $ limit = null ) : array { if ( $ limit === 0 ) { return [ ] ; } $ result = [ ] ; if ( is_dir ( $ dir ) ) { $ list = scandir ( $ dir ) ; if ( is_array ( $ list ) ) { foreach ( $ list as $ filename ) { if ( $ filename != '.' && $ filename != '..' ) { if ( is_dir ( $ dir . $ filename ) ) { if ( $ recursive === true ) { $ dirResult = $ this -> getFiles ( $ dir . $ filename . '/' , true , $ limit !== null ? ( $ limit - sizeof ( $ result ) ) : null ) ; if ( ! empty ( $ dirResult ) ) { foreach ( $ dirResult as $ index => $ value ) { $ dirResult [ $ index ] = $ filename . '/' . $ value ; } $ result = array_merge ( $ result , $ dirResult ) ; } } } else { $ result [ ] = $ filename ; if ( $ limit !== null && $ limit === sizeof ( $ result ) ) { break ; } } } } } } return $ result ; }
Returns list of files in the directory specified.

@param string $dir The directory name.
@param boolean $recursive If TRUE all files in subdirectories will be returned too.
@param int|null $limit Maximum number of files to return.
@return array An array containing list of all files in the directory specified.
Returns list of files in the directory specified .