sorry, wrong version checked in
[phpmyadmin/arisferyanto.git] / libraries / file_listing.php
blobc7a9812c0e88292e987c4aa1cc3151f486493ba4
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
4 // Functions for listing directories
6 /**
7 * Returns array of filtered file names
9 * @param string directory to list
10 * @param string regullar expression to match files
11 * @returns array sorted file list on success, FALSE on failure
13 function PMA_getDirContent($dir, $expression = '') {
14 if ($handle = @opendir($dir)) {
15 $result = array();
16 if (substr($dir, -1) != '/') {
17 $dir .= '/';
19 while ($file = @readdir($handle)) {
20 if (is_file($dir . $file) && ($expression == '' || preg_match($expression, $file))) {
21 $result[] = $file;
24 @closedir($handle);
25 asort($result);
26 return $result;
27 } else {
28 return FALSE;
32 /**
33 * Returns options of filtered file names
35 * @param string directory to list
36 * @param string regullar expression to match files
37 * @param string currently active choice
38 * @returns array sorted file list on success, FALSE on failure
40 function PMA_getFileSelectOptions($dir, $extensions = '', $active = '') {
41 $list = PMA_getDirContent($dir, $extensions);
42 if ($list === FALSE) return FALSE;
43 $result = '';
44 foreach($list as $key => $val) {
45 $result .= '<option value="'. htmlspecialchars($val) . '"';
46 if ($val == $active) {
47 $result .= ' selected="selected"';
49 $result .= '>' . htmlspecialchars($val) . '</option>' . "\n";
51 return $result;
54 /**
55 * Get currently supported decompressions.
57 * @returns string | separated list of extensions usable in PMA_getDirContent
59 function PMA_supportedDecompressions() {
60 global $cfg;
62 $compressions = '';
64 if ($cfg['GZipDump'] && @function_exists('gzopen')) {
65 if (!empty($compressions)) $compressions .= '|';
66 $compressions .= 'gz';
68 if ($cfg['BZipDump'] && @function_exists('bzopen')) {
69 if (!empty($compressions)) $compressions .= '|';
70 $compressions .= 'bz2';
72 if ($cfg['ZipDump'] && @function_exists('gzinflate')) {
73 if (!empty($compressions)) $compressions .= '|';
74 $compressions .= 'zip';
77 return $compressions;