Merge branch 'QA_3_3'
[phpmyadmin/dkf.git] / libraries / file_listing.php
blobff9e1a8c888990000954faf50f134eb16372336c
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Functions for listing directories
6 * @todo rename to file_listing.lib.php
7 * @version $Id$
8 * @package phpMyAdmin
9 */
11 /**
12 * Returns array of filtered file names
14 * @param string directory to list
15 * @param string regular expression to match files
16 * @returns array sorted file list on success, FALSE on failure
18 function PMA_getDirContent($dir, $expression = '')
20 if (file_exists($dir) && $handle = @opendir($dir)) {
21 $result = array();
22 if (substr($dir, -1) != '/') {
23 $dir .= '/';
25 while ($file = @readdir($handle)) {
26 // for PHP < 5.2.4, is_file() gives a warning when using open_basedir
27 // and verifying '..' or '.'
28 if ('.' != $file && '..' != $file && is_file($dir . $file) && ($expression == '' || preg_match($expression, $file))) {
29 $result[] = $file;
32 @closedir($handle);
33 asort($result);
34 return $result;
35 } else {
36 return FALSE;
40 /**
41 * Returns options of filtered file names
43 * @param string directory to list
44 * @param string regullar expression to match files
45 * @param string currently active choice
46 * @returns array sorted file list on success, FALSE on failure
48 function PMA_getFileSelectOptions($dir, $extensions = '', $active = '')
50 $list = PMA_getDirContent($dir, $extensions);
51 if ($list === FALSE) {
52 return FALSE;
54 $result = '';
55 foreach ($list as $key => $val) {
56 $result .= '<option value="'. htmlspecialchars($val) . '"';
57 if ($val == $active) {
58 $result .= ' selected="selected"';
60 $result .= '>' . htmlspecialchars($val) . '</option>' . "\n";
62 return $result;
65 /**
66 * Get currently supported decompressions.
68 * @returns string | separated list of extensions usable in PMA_getDirContent
70 function PMA_supportedDecompressions()
72 global $cfg;
74 $compressions = '';
76 if ($cfg['GZipDump'] && @function_exists('gzopen')) {
77 if (!empty($compressions)) {
78 $compressions .= '|';
80 $compressions .= 'gz';
82 if ($cfg['BZipDump'] && @function_exists('bzopen')) {
83 if (!empty($compressions)) {
84 $compressions .= '|';
86 $compressions .= 'bz2';
88 if ($cfg['ZipDump'] && @function_exists('gzinflate')) {
89 if (!empty($compressions)) {
90 $compressions .= '|';
92 $compressions .= 'zip';
95 return $compressions;