another case for bug 1759194
[phpmyadmin/crack.git] / libraries / file_listing.php
blob96a9bd887ca36d208a4cf0a4dfd34f1363a2fa8b
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 regular 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 // for PHP < 5.2.4, is_file() gives a warning when using open_basedir
25 // and verifying '..' or '.'
26 if ('.' != $file && '..' != $file && is_file($dir . $file) && ($expression == '' || preg_match($expression, $file))) {
27 $result[] = $file;
30 @closedir($handle);
31 asort($result);
32 return $result;
33 } else {
34 return FALSE;
38 /**
39 * Returns options of filtered file names
41 * @param string directory to list
42 * @param string regullar expression to match files
43 * @param string currently active choice
44 * @returns array sorted file list on success, FALSE on failure
46 function PMA_getFileSelectOptions($dir, $extensions = '', $active = '')
48 $list = PMA_getDirContent($dir, $extensions);
49 if ($list === FALSE) {
50 return FALSE;
52 $result = '';
53 foreach ($list as $key => $val) {
54 $result .= '<option value="'. htmlspecialchars($val) . '"';
55 if ($val == $active) {
56 $result .= ' selected="selected"';
58 $result .= '>' . htmlspecialchars($val) . '</option>' . "\n";
60 return $result;
63 /**
64 * Get currently supported decompressions.
66 * @returns string | separated list of extensions usable in PMA_getDirContent
68 function PMA_supportedDecompressions()
70 global $cfg;
72 $compressions = '';
74 if ($cfg['GZipDump'] && @function_exists('gzopen')) {
75 if (!empty($compressions)) {
76 $compressions .= '|';
78 $compressions .= 'gz';
80 if ($cfg['BZipDump'] && @function_exists('bzopen')) {
81 if (!empty($compressions)) {
82 $compressions .= '|';
84 $compressions .= 'bz2';
86 if ($cfg['ZipDump'] && @function_exists('gzinflate')) {
87 if (!empty($compressions)) {
88 $compressions .= '|';
90 $compressions .= 'zip';
93 return $compressions;