Zend - The PHP Company




Files and Directories

Add Code


F&DB&CV2  

Type: code fragment
Added by: abadon
Entered: 04/07/2002
Last modified: 07/12/2001
Rating: - (fewer than 3 votes)
Views: 6122
Files and Directories Browser and Source Code Viewer... not anything special


<?php
//Script browse any directory, print out its content,
//contents of dir. contain files (so-called; "source code")
//and make HyperLinks for execute each one file or directory
//Script work in Win2000/IIS 5/PHP 4.2.1 and working with older
//versions of PHP, too, but in Linux/Apache must specified
//full server path in "opendir" function attribute...

$PHP_SELF $_POST['PHP_SELF'];
$s $_POST['s'];
@
$a $_POST['a'];
@
$A = @$a;
@
$all file($A);
$n count($all);
//Source Code Echo Out design function (Strings, Tags and Text).
//Will be nice to add Browser Detecting and some Style Sheets...
function source($draw)
{
    
$color1 "000000";
    
$color2 "AA0000";
    
$color3 "0000BB";
    
$draw chop($draw);
    
$segment split("/(<|>)/"$draw);
    
$n count($segment);
    for (
$x 0;  $x $n;  $x++)
    {
        
$part $segment[$x];
        
$part htmlspecialchars($part);
        
$search '/&quot;.*?&quot;/';
        
$new "<font color=#$color1>\0</font>";

        
$part preg_replace($search$new$part);
        
$search '/&lt;.*?&gt;/';
        
$new "<font color=$color2>\0</font>";

        
$part preg_replace($search$new$part);
        
$segment[$x] = $part;
    }
    
$draw join(""$segment);
    
$draw "<font color=$color3>".$draw."</font>n";
    return 
$draw ;
}
//open directory and write out all of contents...
//Linux/Apache enviroinment request full path entered
//i.e. "$dh = opendir("/raid/home/my_dir01/html/www.my_domain.com/");"
/*error_reporting (E_ALL);*/
$dh opendir("");
if (!
$dh)
{
    die(
"failed to open directory");
}
    echo (
"<table border="0" width="100%">"."<tr>"."<td width="20%" valign="top">");
    echo (
"<table border="0" width="100%">");
$s readdir($dh);
while (
$s)
{
//security: uncomment, if you want block access (via H_Link) to parent (or root, too)
//directories, and make "directory default document"(i.e. index.php) with safe contents,
//... and,of course, secure directories must be correct sequenced
    /*$s=ereg_replace("(..)+","",$s);*/
    
//create HyperLinks and HTML Form with Radio Boxes Elements for
//source code view selection and Submit Button for each one...
    
echo ("<tr>"."<td width="50%">");
    echo (
"<a href="$s">$s</a>".
    
"</td>"."<td width="50%" valign="top">".
    
"<form action="$PHP_SELF" method="POST">".
    
"<input type="submit" value="SRC:->" />".
    
"<input type="radio" name="a" value="$s" />".
    
"<br>");
    
$s readdir($dh);
}
closedir($dh);
    echo (
"</td>"."</tr>"."</table>");
    echo (
"<td width="80%" valign="top">");
    echo (
"<table border="0" width="100%">");
    echo (
"<tr>"."<td width="100%" valign="top">");
//out write tag and counter
echo "<PRE>n";
for( 
$i 0;  $i $n;  $i++ )
{
//uncomment for code rows counting (poor looking `cause of... print out in cells
//is "not yet implemented")
    /*echo $i + 1;*/
//print out
    
echo source($all[$i]);
}
echo 
"</PRE>n";
    echo (
"</td>"."</tr>"."</table>");
    echo (
"</td>"."</tr>"."</table>");
//etc...
//author e-mail: brane.slevec@telesat.si
?>


Usage Example


Just check Radio Button and press Submit Button or execute hyperlink...


Rate This Script





Search



This Category All Categories