/** * Context is an array with these keys: * isExpanded an array of absolute dir names mapped to booleans */ function display($context) { echo $this->pageHeader("View & download files", "files"); $list = listRecursive($_SESSION['dataDir']); $list = sortFilesAlpha($list); $this->displayDownloadForm($list, $context['isExpanded']); echo $this->pageFooter(); }
function displayAllFiles($context) { echo "<h5 class='welcome'>Popular Downloads (<a href='" . makeEventURL('onCall', 'file_browser.php') . "'>all downloads</a>)</h5>\n"; echo "<div class='indent'>\n"; $list = listRecursive($_SESSION['dataDir']); unset($list[MP_DIR_SYSTEM]); unset($list[MP_DIR_WORK]); unset($list[MP_DIR_RAWDATA]); $list = sortFilesAlpha($list); $this->displayDownloadForm($list, $context['isExpanded']); echo "</div>\n"; // end indent }
/** * Returns an array of file and/or directory names. * File names will be strings, and directory names will be arrays with * the key set to the name of the directory. Test with is_array(). * Keys for files are the same as the values (i.e. the file name). * Returns FALSE on failure. */ function listRecursive($dir) { if ($handle = opendir($dir)) { $list = array(); while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $path = "{$dir}/{$file}"; if (is_dir($path)) { $sublist = listRecursive($path); if ($sublist !== false) { $list[$file] = $sublist; } } else { $list[$file] = $file; } } } closedir($handle); return $list; } else { return false; } }