Mega Code Archive

 
Categories / Php / File Directory
 

Error Log Finder

<html><body> <?php function GetListArray( $fileRoot, $matchFile, $isWin) { $foundList = array(); $subList = array(); $filePath = ""; //file path relative to current file $ web directories $path = $fileRoot; do { $path = $fileRoot.$filePath; $Hdir = opendir($path); if ($Hdir) { while (false !== ($file = readdir($Hdir))) { if (($file != '.') && ($file != '..')) { if ($isWin) { if ($file === $matchFile) array_push($foundList, $filePath."\\".$file); if (is_dir( $fileRoot.$filePath."\\".$file )) array_push($subList, $filePath."\\".$file); } // if isWin else { if ($file === $matchFile) array_push($foundList, $filePath.'/'.$file); if (is_dir( $fileRoot.$filePath.'/'.$file )) array_push($subList, $filePath.'/'.$file); } // else isWin } // if . or .. } // while file }// if Hdir $continue= false; if (list($key, $val)= each($subList)) { $continue=true; $filePath = $val; array_shift($subList); } // if subList } while ($continue); sort($foundList); return $foundList; } // GetListArray function; // main code if (isset($_GET['delete'])) { $tmp = $_GET['delete']; // var_dump($tmp); unlink($tmp); } $errFile = ini_get('error_log'); $me = $_SERVER['SCRIPT_NAME']; $sub = substr( $_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')); $webRoot = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$sub; $dirRoot = getcwd(); $isWin = (strrpos($dirRoot, '\\')=== FALSE) ? FALSE : TRUE; $List = GetListArray( $dirRoot, $errFile, $isWin); ?> <table width="100%" border="1" cellspacing="2" cellpadding="0"> <tr> <td></td> <td><p>List of all log files (specified by "error_log" in php.ini file) at or below the current directory.</p> <?php print "<p>error_log setting: $errFile</p>\n"; print "<p>current web directory: $webRoot</p>\n"; print "<p>current file direcory: $dirRoot</p>\n"; foreach ($List as $dir){ $tmp = str_replace("\\", '/', $dir); $ds = $me.'?delete='.$dirRoot.$dir; print '<tr><td><a href="'.$webRoot.$tmp.'" target="_blank">view</a></td><td>'.$dir.'</td><td><a href="'.$ds.'">delete</a></td></tr>'."\n"; } // foreach list print '<tr><td></td><td><form action ="'.$me.'" method="get" name="FindErrLog">'."\n"; ?> <p><input type="submit" name="bnStart" value="Search" border="0"></p> </form></td> </table> </body> </html> <?php flush(); exit; ?>