File Manipulation Code

  Home arrow File Manipulation Code arrow Error Log Finder
FILE MANIPULATION CODE

Error Log Finder
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2003-05-13

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    Script to find error log files (specified by php.ini) at and below current directory. With option to view or delete files.

    By : opus006

    <html><body>
    <?php
    /*
    script: FindErrLog
    by: Wayne Nelson
    for: codewalkers code forum

    scrip to display all error logs at, or below current directory.
    Uses log file specified in php.ini: error_log=XXXXXXXXXX

    */

    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;
    ?>

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More File Manipulation Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    FILE MANIPULATION CODE ARTICLES

    - Bandwidth Control with pure PHP
    - Eazy Gallery
    - file_get_contents for PHP < 4.3.0
    - PHP Class: Image Snapshot 1.3
    - Universal downloader
    - Image Gallery v2.0
    - Free/Used Disk Space
    - Directory Lister
    - Directory image view, with selective hidden
    - Move or Copy a Directory (and files and sub ...
    - Ensure_Sub_Directory_Exists
    - Wedit
    - Form Examples Text Boxes to Drop Downs
    - myFiles
    - List files in a directory, no subdirectories


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap