Traverse Directory Tree



' . "\n"; if (strpos(strtolower($_SERVER['SERVER_NAME']), 'rjmprogramming.com.au') !== false || strpos(strtolower($_SERVER['SERVER_PORT']), '8888') !== false) { echo 'Domain:

' . "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . "/" . '


' . "\n"; echo '
' . "\n"; echo 'Subdirectory (end with ' . DIRECTORY_SEPARATOR . '):

'; } else { echo 'Domain:
' . "\n"; echo '
' . "\n"; echo 'Subdirectory (end with ' . DIRECTORY_SEPARATOR . '):

'; } echo ' Find 1 of 2 (optional):
Find 2 of 2 (optional):

'; } else if (isset($_GET['fix'])) { $hdr = ""; $onhdr = ""; if (1 == 3 && (strpos(strtolower($_SERVER['SERVER_NAME']), 'rjmprogramming.com.au') !== false || strpos(strtolower($_SERVER['SERVER_PORT']), '8888') !== false)) { $hdr = ""; $onhdr = ' onload=" onloadf(); " '; } echo ' ' . $hdr . ' '; exit; } else { set_time_limit(0); $suffix = ""; $dirs = array(); $dir = dirname(__FILE__) . "/"; $fdir = ""; $inspec1 = ''; $inspec2 = ''; $icnt = 0; if ($argv) { foreach ($argv as $arg) { // PHP command line if ($icnt == 0) { if (strpos(urldecode($arg), ".php") === false) $dir = urldecode($arg); if (strpos(urldecode($arg), ".php") === false) $fdir = $dir; } else if ($icnt == 1) { $inspec1 = urldecode($arg); } else if ($icnt == 2) { $inspec2 = urldecode($arg); } if (strpos(urldecode($arg), ".php") === false) $icnt = $icnt + 1; } } if (isset($_GET['subdirectory']) || isset($_POST['subdirectory'])) { // web browsing $hdr = ""; $onhdr = ""; if (1 == 2 && (strpos(strtolower($_SERVER['SERVER_NAME']), 'rjmprogramming.com.au') !== false || strpos(strtolower($_SERVER['SERVER_PORT']), '8888') !== false)) { $hdr = ""; $onhdr = ' onload=" onloadf(); " '; } echo ' ' . $hdr . '

Traverse Directory Tree Results



'; } // business logic if (isset($_GET['dir'])) { // curl (parameterising idea) or web browsing later $swstuff = explode("@", urldecode($_GET['dir'])); if (sizeof($swstuff) == 1) { $dir = urldecode($_GET['dir']); } else { $dir = urldecode($swstuff[0]); if (sizeof($swstuff) >= 2) $inspec1 = urldecode($swstuff[1]); if (sizeof($swstuff) >= 3) $inspec2 = urldecode($swstuff[3]); } $fdir = $dir; } if (isset($_GET['inspec1'])) { $inspec1 = urldecode($_GET['inspec1']); } if (isset($_GET['inspec2'])) { $inspec2 = urldecode($_GET['inspec2']); } if (isset($_POST['dir'])) { // curl parameterising idea $swstuff = explode("@", urldecode($_POST['dir'])); if (sizeof($swstuff) == 1) { $dir = urldecode($_POST['dir']); } else { $dir = urldecode($swstuff[0]); if (sizeof($swstuff) >= 2) $inspec1 = urldecode($swstuff[1]); if (sizeof($swstuff) >= 3) $inspec2 = urldecode($swstuff[3]); } $fdir = $dir; } if (isset($_POST['inspec1'])) { $inspec1 = urldecode($_POST['inspec1']); } if (isset($_POST['inspec2'])) { $inspec2 = urldecode($_POST['inspec2']); } if (strpos(strtolower($_SERVER['SERVER_NAME']), 'rjmprogramming.com.au') !== false || strpos(strtolower($_SERVER['SERVER_PORT']), '8888') !== false) { $dir = str_replace("http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . "/", str_replace("PHP/", "/", dirname(__FILE__) . "/"), $dir); } $result = array(); function moredirs($inidea) { global $dirs; $idirs = 0; $dirs[sizeof($dirs)] = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $inidea); $cdir = scandir($inidea); foreach ($cdir as $key => $value) { if (!in_array($value,array(".",".."))) { if (is_dir($inidea . DIRECTORY_SEPARATOR . $value)) { moredirs($inidea . DIRECTORY_SEPARATOR . $value); return 1; } } } return $idirs; } $dirs[sizeof($dirs)] = $dir; if (trim($fdir) == "") { $cdir = scandir($dir); foreach ($cdir as $key => $value) { if (!in_array($value,array(".",".."))) { if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) { moredirs($dir . DIRECTORY_SEPARATOR . $value); } } } } if (sizeof($dirs) >= 1) { for ($j=0; $j= 1) { for ($j=0; $j

Directories ...


" . $fis . " ...

'; } else { echo "\n\nDirectories ...\n"; print_r($dirs); echo "\n\n" . $fis . " ...\n"; print_r($result); } // business logic } ?>