2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Functions for listing directories
6 * @todo rename to file_listing.lib.php
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)) {
22 if (substr($dir, -1) != '/') {
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))) {
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) {
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";
66 * Get currently supported decompressions.
68 * @returns string | separated list of extensions usable in PMA_getDirContent
70 function PMA_supportedDecompressions()
76 if ($cfg['GZipDump'] && @function_exists
('gzopen')) {
77 if (!empty($compressions)) {
80 $compressions .= 'gz';
82 if ($cfg['BZipDump'] && @function_exists
('bzopen')) {
83 if (!empty($compressions)) {
86 $compressions .= 'bz2';
88 if ($cfg['ZipDump'] && @function_exists
('gzinflate')) {
89 if (!empty($compressions)) {
92 $compressions .= 'zip';