Merge remote-tracking branch 'origin/QA_4_0' into QA_4_0
[phpmyadmin.git] / libraries / file_listing.lib.php
blobe5b680c2caf0f00728056b16462e4b1e1f4bc5a2
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Functions for listing directories
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * Returns array of filtered file names
15 * @param string $dir directory to list
16 * @param string $expression regular expression to match files
18 * @return array sorted file list on success, false on failure
20 function PMA_getDirContent($dir, $expression = '')
22 if (file_exists($dir) && $handle = @opendir($dir)) {
23 $result = array();
24 if (substr($dir, -1) != '/') {
25 $dir .= '/';
27 while ($file = @readdir($handle)) {
28 // for PHP < 5.2.4, is_file() gives a warning when using open_basedir
29 // and verifying '..' or '.'
30 if ('.' != $file
31 && '..' != $file
32 && is_file($dir . $file)
33 && ($expression == '' || preg_match($expression, $file))
34 ) {
35 $result[] = $file;
38 @closedir($handle);
39 asort($result);
40 return $result;
41 } else {
42 return false;
46 /**
47 * Returns options of filtered file names
49 * @param string $dir directory to list
50 * @param string $extensions regullar expression to match files
51 * @param string $active currently active choice
53 * @return array sorted file list on success, false on failure
55 function PMA_getFileSelectOptions($dir, $extensions = '', $active = '')
57 $list = PMA_getDirContent($dir, $extensions);
58 if ($list === false) {
59 return false;
61 $result = '';
62 foreach ($list as $val) {
63 $result .= '<option value="'. htmlspecialchars($val) . '"';
64 if ($val == $active) {
65 $result .= ' selected="selected"';
67 $result .= '>' . htmlspecialchars($val) . '</option>' . "\n";
69 return $result;
72 /**
73 * Get currently supported decompressions.
75 * @return string | separated list of extensions usable in PMA_getDirContent
77 function PMA_supportedDecompressions()
79 global $cfg;
81 $compressions = '';
83 if ($cfg['GZipDump'] && @function_exists('gzopen')) {
84 if (!empty($compressions)) {
85 $compressions .= '|';
87 $compressions .= 'gz';
89 if ($cfg['BZipDump'] && @function_exists('bzopen')) {
90 if (!empty($compressions)) {
91 $compressions .= '|';
93 $compressions .= 'bz2';
95 if ($cfg['ZipDump'] && @function_exists('gzinflate')) {
96 if (!empty($compressions)) {
97 $compressions .= '|';
99 $compressions .= 'zip';
102 return $compressions;