Translated using Weblate (Danish)
[phpmyadmin.git] / libraries / file_listing.lib.php
blobfbeed49763d9454bbfe9efbd26053a6cb8aaf2f7
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Functions for listing directories
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * Returns array of filtered file names
15 * @param string $dir directory to list
16 * @param string $expression regular expression to match files
18 * @return array sorted file list on success, false on failure
20 function PMA_getDirContent($dir, $expression = '')
22 if (file_exists($dir) && $handle = @opendir($dir)) {
23 $result = array();
24 if (substr($dir, -1) != '/') {
25 $dir .= '/';
27 while ($file = @readdir($handle)) {
28 if (is_file($dir . $file)
29 && ($expression == '' || preg_match($expression, $file))
30 ) {
31 $result[] = $file;
34 @closedir($handle);
35 asort($result);
36 return $result;
37 } else {
38 return false;
42 /**
43 * Returns options of filtered file names
45 * @param string $dir directory to list
46 * @param string $extensions regullar expression to match files
47 * @param string $active currently active choice
49 * @return array sorted file list on success, false on failure
51 function PMA_getFileSelectOptions($dir, $extensions = '', $active = '')
53 $list = PMA_getDirContent($dir, $extensions);
54 if ($list === false) {
55 return false;
57 $result = '';
58 foreach ($list as $val) {
59 $result .= '<option value="'. htmlspecialchars($val) . '"';
60 if ($val == $active) {
61 $result .= ' selected="selected"';
63 $result .= '>' . htmlspecialchars($val) . '</option>' . "\n";
65 return $result;
68 /**
69 * Get currently supported decompressions.
71 * @return string | separated list of extensions usable in PMA_getDirContent
73 function PMA_supportedDecompressions()
75 global $cfg;
77 $compressions = '';
79 if ($cfg['GZipDump'] && @function_exists('gzopen')) {
80 if (!empty($compressions)) {
81 $compressions .= '|';
83 $compressions .= 'gz';
85 if ($cfg['BZipDump'] && @function_exists('bzopen')) {
86 if (!empty($compressions)) {
87 $compressions .= '|';
89 $compressions .= 'bz2';
91 if ($cfg['ZipDump'] && @function_exists('gzinflate')) {
92 if (!empty($compressions)) {
93 $compressions .= '|';
95 $compressions .= 'zip';
98 return $compressions;