2.11.1.2 release
[phpmyadmin/arisferyanto.git] / libraries / file_listing.php
blob5a71dd0c429bd469d0c75a86f3f09a1b9febec51
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Functions for listing directories
6 * @version $Id$
7 */
9 /**
10 * Returns array of filtered file names
12 * @param string directory to list
13 * @param string regullar expression to match files
14 * @returns array sorted file list on success, FALSE on failure
16 function PMA_getDirContent($dir, $expression = '')
18 if ($handle = @opendir($dir)) {
19 $result = array();
20 if (substr($dir, -1) != '/') {
21 $dir .= '/';
23 while ($file = @readdir($handle)) {
24 if (is_file($dir . $file) && ($expression == '' || preg_match($expression, $file))) {
25 $result[] = $file;
28 @closedir($handle);
29 asort($result);
30 return $result;
31 } else {
32 return FALSE;
36 /**
37 * Returns options of filtered file names
39 * @param string directory to list
40 * @param string regullar expression to match files
41 * @param string currently active choice
42 * @returns array sorted file list on success, FALSE on failure
44 function PMA_getFileSelectOptions($dir, $extensions = '', $active = '')
46 $list = PMA_getDirContent($dir, $extensions);
47 if ($list === FALSE) {
48 return FALSE;
50 $result = '';
51 foreach ($list as $key => $val) {
52 $result .= '<option value="'. htmlspecialchars($val) . '"';
53 if ($val == $active) {
54 $result .= ' selected="selected"';
56 $result .= '>' . htmlspecialchars($val) . '</option>' . "\n";
58 return $result;
61 /**
62 * Get currently supported decompressions.
64 * @returns string | separated list of extensions usable in PMA_getDirContent
66 function PMA_supportedDecompressions()
68 global $cfg;
70 $compressions = '';
72 if ($cfg['GZipDump'] && @function_exists('gzopen')) {
73 if (!empty($compressions)) {
74 $compressions .= '|';
76 $compressions .= 'gz';
78 if ($cfg['BZipDump'] && @function_exists('bzopen')) {
79 if (!empty($compressions)) {
80 $compressions .= '|';
82 $compressions .= 'bz2';
84 if ($cfg['ZipDump'] && @function_exists('gzinflate')) {
85 if (!empty($compressions)) {
86 $compressions .= '|';
88 $compressions .= 'zip';
91 return $compressions;