src/File/FileUtil.php
public function getFileList($dir, $baseUrl, $protectedBaseUrl = null)
    {
        $results = [];

        if (is_dir($dir)) {
            if ($handler = opendir($dir)) {
                while (false !== ($file = readdir($handler))) {
                    if ('.' == substr($file, 0, 1)) {
                        continue;
                    }

                    $fileArray = [];
                    $fileArray['filename'] = htmlentities($file);

                    if ($protectedBaseUrl) {
                        $fileArray['absUrl'] =
                            $protectedBaseUrl.(empty($_GET) ? '?' : '&').'file='.str_replace('//', '', $baseUrl.'/'.$file);
                    } else {
                        $fileArray['absUrl'] = str_replace('\\', '/', str_replace('//', '', $baseUrl.'/'.$file));
                    }

                    $fileArray['path'] = str_replace($fileArray['filename'], '', $fileArray['absUrl']);
                    $fileArray['filesize'] =
                        $this->formatSizeUnits(filesize(str_replace('\\', '/', str_replace('//', '', $dir.'/'.$file))), true);

                    $results[] = $fileArray;
                }

                closedir($handler);
            }
        }

        $this->container->get('huh.utils.array')->aasort($results, 'filename');

        return $results;
    }
public function getFileList($dir, $baseUrl, $protectedBaseUrl = null)
    {
        $results = [];

        if (is_dir($dir)) {
            if ($handler = opendir($dir)) {
                while (false !== ($file = readdir($handler))) {
                    if ('.' == substr($file, 0, 1)) {
                        continue;
                    }

                    $fileArray = [];
                    $fileArray['filename'] = htmlentities($file);

                    if ($protectedBaseUrl) {
                        $fileArray['absUrl'] =
                            $protectedBaseUrl.(empty($_GET) ? '?' : '&').'file='.str_replace('//', '', $baseUrl.'/'.$file);
                    } else {
                        $fileArray['absUrl'] = str_replace('\\', '/', str_replace('//', '', $baseUrl.'/'.$file));
                    }

                    $fileArray['path'] = str_replace($fileArray['filename'], '', $fileArray['absUrl']);
                    $fileArray['filesize'] =
                        $this->formatSizeUnits(filesize(str_replace('\\', '/', str_replace('//', '', $dir.'/'.$file))), true);

                    $results[] = $fileArray;
                }

                closedir($handler);
            }
        }

        $this->container->get('huh.utils.array')->aasort($results, 'filename');

        return $results;
    }
public function getFileList ( $ dir , $ baseUrl , $ protectedBaseUrl = null ) { $ results = [ ] ; if ( is_dir ( $ dir ) ) { if ( $ handler = opendir ( $ dir ) ) { while ( false !== ( $ file = readdir ( $ handler ) ) ) { if ( '.' == substr ( $ file , 0 , 1 ) ) { continue ; } $ fileArray = [ ] ; $ fileArray [ 'filename' ] = htmlentities ( $ file ) ; if ( $ protectedBaseUrl ) { $ fileArray [ 'absUrl' ] = $ protectedBaseUrl . ( empty ( $ _GET ) ? '?' : '&' ) . 'file=' . str_replace ( '//' , '' , $ baseUrl . '/' . $ file ) ; } else { $ fileArray [ 'absUrl' ] = str_replace ( '\\' , '/' , str_replace ( '//' , '' , $ baseUrl . '/' . $ file ) ) ; } $ fileArray [ 'path' ] = str_replace ( $ fileArray [ 'filename' ] , '' , $ fileArray [ 'absUrl' ] ) ; $ fileArray [ 'filesize' ] = $ this -> formatSizeUnits ( filesize ( str_replace ( '\\' , '/' , str_replace ( '//' , '' , $ dir . '/' . $ file ) ) ) , true ) ; $ results [ ] = $ fileArray ; } closedir ( $ handler ) ; } } $ this -> container -> get ( 'huh.utils.array' ) -> aasort ( $ results , 'filename' ) ; return $ results ; }
Returns the file list for a given directory.

@param string $dir              - the absolute local path to the directory (e.g. /dir/mydir)
@param string $baseUrl          - the relative uri (e.g. /tl_files/mydir)
@param string $protectedBaseUrl - domain + request uri -> absUrl will be domain + request uri + ?file=$baseUrl/filename.ext

@return array file list containing file objects
Returns the file list for a given directory .