Viewing ./source.php Filesize: 4.33Kb
<?php
//*****************************************************************************
//
// MICRO FILE BROWSER  -  Version: 1.0
//
// You may use this code or any modified version of it on your website.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind, either
// expressed or implied, including, but not limited to, the implied warranties
// of merchantability and fitness for a particular purpose. You expressly
// acknowledge and agree that use of this code is at your own risk.
//
//*****************************************************************************

function showContent($path){


   if (
$handle opendir($path))
   {
       
//this link takes us one level higher in the directory
       
$up substr($path0, (strrpos(dirname($path."/."),"/")));
       echo 
"<tr><td colspan='2'><img src='style/up2.gif' width='16' height='16' alt='up'/> <a href='".$_SERVER['PHP_SELF']."?path=$up'>Up one level</a></td></tr>";

       while (
false !== ($file readdir($handle)))
       
//In this step we will create a function to list all entries in the given directory. To do this PHP has a built in function called readdir().
       
{
           if (
$file != "." && $file != "..")
           {
               
$fName $file;
               
$file $path.'/'.$file;
               if(
is_file($file)) {
               
//if it's a page document, we will make a link to document  
               // I added the next line using a separate file view.php which actually shows the source code of a document on your server. You can view the source for view.php too
               //Lastly, you can print out timestamp and filesize info as shown in the last to table data entries
               
               
echo "<tr><td><img src='style/file2.gif' width='16' height='16' alt='file'/> 
               <a href='"
.$file."'>".$fName."</a></td>" 
                           
                            
."<td><a href='http://galiwood.com/javascript/view.php?file=".$file."'>[Source]</a></td>" 
                   
                            
."<td align='right'>".date ('d-m-Y H:i:s'filemtime($file))."</td>"
                            
."<td align='right'>".filesize($file)." bytes</td></tr>";
               } elseif (
is_dir($file)) {
                   
                   
//use a different image for a directory and the link opens the same page with the new link (basically this is an iteration in order to dig deeper into the site)
                   
print "<tr><td colspan='2'><img src='style/dir2.gif' width='16' height='16' alt='dir'/> <a href='".$_SERVER['PHP_SELF']."?path=$file'>$fName</a></td></tr>";
               }
           }
       }

       
closedir($handle);
   }    

}

if (isset(
$_POST['submitBtn'])){
    
$actpath = isset($_POST['path']) ? $_POST['path'] : '.';    
} else {
    
$actpath = isset($_GET['path']) ? $_GET['path'] : '.';    
}


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>Gali's Web Sources</title>
   <link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="main">
      <div class="caption">Gali's Web Source Files</div>
      <div id="icon">&nbsp;</div>
      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="path">
      
<!-- 'PHP_SELF' - The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar. The __FILE__ constant contains the full path and filename of the current (i.e. included) file.
 If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. Previously it was not available. 
 I obtained this defn. from http://us.php.net/reserved.variables-->
        
        <table width="100%">
          <tr><td>Path: <input class="text" name="path" type="text" size="40" value="<?php echo $actpath?>" /></td></tr>
          <tr><td align="center"><br/><input class="text" type="submit" name="submitBtn" value="List content" /></td></tr>
        </table>  
      </form><br/>

      <div class="caption">ACTUAL PATH: <?php echo $actpath ?></div>
      <div id="icon2">&nbsp;</div>
      <div id="result">
        <table width="100%">
        <?php
            showContent
($actpath);     
            
//we call our function that will parse and show links and images of the sitemap on the page            
        
?>
        </table>
     </div>
    <div id="source">Micro File Browser 1.0</div>
    </div>
</body>