2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Functions for listing directories
6 * @todo rename to file_listing.lib.php
11 * Returns array of filtered file names
13 * @param string $dir directory to list
14 * @param string $expression regular expression to match files
15 * @return array sorted file list on success, false on failure
17 function PMA_getDirContent($dir, $expression = '')
19 if (file_exists($dir) && $handle = @opendir
($dir)) {
21 if (substr($dir, -1) != '/') {
24 while ($file = @readdir
($handle)) {
25 // for PHP < 5.2.4, is_file() gives a warning when using open_basedir
26 // and verifying '..' or '.'
27 if ('.' != $file && '..' != $file && is_file($dir . $file) && ($expression == '' ||
preg_match($expression, $file))) {
40 * Returns options of filtered file names
42 * @param string $dir directory to list
43 * @param string $extensions regullar expression to match files
44 * @param string $active currently active choice
45 * @return array sorted file list on success, false on failure
47 function PMA_getFileSelectOptions($dir, $extensions = '', $active = '')
49 $list = PMA_getDirContent($dir, $extensions);
50 if ($list === false) {
54 foreach ($list as $key => $val) {
55 $result .= '<option value="'. htmlspecialchars($val) . '"';
56 if ($val == $active) {
57 $result .= ' selected="selected"';
59 $result .= '>' . htmlspecialchars($val) . '</option>' . "\n";
65 * Get currently supported decompressions.
67 * @return string | separated list of extensions usable in PMA_getDirContent
69 function PMA_supportedDecompressions()
75 if ($cfg['GZipDump'] && @function_exists
('gzopen')) {
76 if (!empty($compressions)) {
79 $compressions .= 'gz';
81 if ($cfg['BZipDump'] && @function_exists
('bzopen')) {
82 if (!empty($compressions)) {
85 $compressions .= 'bz2';
87 if ($cfg['ZipDump'] && @function_exists
('gzinflate')) {
88 if (!empty($compressions)) {
91 $compressions .= 'zip';