1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: namespace Xoops\Core\Lists;
13:
14: /**
15: * File - provide list of file names from a directory
16: *
17: * @category Xoops\Core\Lists\File
18: * @package Xoops\Core
19: * @author Richard Griffith <richard@geekwright.com>
20: * @copyright 2015 XOOPS Project (http://xoops.org)/
21: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22: * @link http://xoops.org
23: */
24: class File extends ListAbstract
25: {
26: /**
27: * gets list of all files in a directory
28: *
29: * @param string $path filesystem path
30: * @param string $prefix prefix added to file names
31: *
32: * @return array
33: */
34: public static function getList($path = '', $prefix = '')
35: {
36: $fileList = array();
37: $path = rtrim($path, '/');
38: if (is_dir($path) && $handle = opendir($path)) {
39: while (false !== ($file = readdir($handle))) {
40: if (!preg_match('/^[\.]{1,2}$/', $file) && is_file($path . '/' . $file)) {
41: $file = $prefix . $file;
42: $fileList[$file] = $file;
43: }
44: }
45: closedir($handle);
46: asort($fileList);
47: reset($fileList);
48: }
49:
50: return $fileList;
51: }
52: }
53: