incorrect XHTNL attribute
[phpmyadmin/crack.git] / libraries / file_listing.php
blob8f6c0a6cda76500e2d2bbebc40317496baf29827
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 */
10 /**
11 * Returns array of filtered file names
13 * @param string directory to list
14 * @param string regular expression to match files
15 * @returns array sorted file list on success, FALSE on failure
17 function PMA_getDirContent($dir, $expression = '')
19 if (file_exists($dir) && $handle = @opendir($dir)) {
20 $result = array();
21 if (substr($dir, -1) != '/') {
22 $dir .= '/';
24 while ($file = @readdir($handle)) {
25 // for PHP < 5.2.4, is_file() gives a warning when using open_basedir
26 // and verifying '..' or '.'
27 if ('.' != $file && '..' != $file && is_file($dir . $file) && ($expression == '' || preg_match($expression, $file))) {
28 $result[] = $file;
31 @closedir($handle);
32 asort($result);
33 return $result;
34 } else {
35 return FALSE;
39 /**
40 * Returns options of filtered file names
42 * @param string directory to list
43 * @param string regullar expression to match files
44 * @param string currently active choice
45 * @returns array sorted file list on success, FALSE on failure
47 function PMA_getFileSelectOptions($dir, $extensions = '', $active = '')
49 $list = PMA_getDirContent($dir, $extensions);
50 if ($list === FALSE) {
51 return FALSE;
53 $result = '';
54 foreach ($list as $key => $val) {
55 $result .= '<option value="'. htmlspecialchars($val) . '"';
56 if ($val == $active) {
57 $result .= ' selected="selected"';
59 $result .= '>' . htmlspecialchars($val) . '</option>' . "\n";
61 return $result;
64 /**
65 * Get currently supported decompressions.
67 * @returns string | separated list of extensions usable in PMA_getDirContent
69 function PMA_supportedDecompressions()
71 global $cfg;
73 $compressions = '';
75 if ($cfg['GZipDump'] && @function_exists('gzopen')) {
76 if (!empty($compressions)) {
77 $compressions .= '|';
79 $compressions .= 'gz';
81 if ($cfg['BZipDump'] && @function_exists('bzopen')) {
82 if (!empty($compressions)) {
83 $compressions .= '|';
85 $compressions .= 'bz2';
87 if ($cfg['ZipDump'] && @function_exists('gzinflate')) {
88 if (!empty($compressions)) {
89 $compressions .= '|';
91 $compressions .= 'zip';
94 return $compressions;