CODE FOLLOWS
<?php
error_reporting(E_ALL); // set error reporting to all
$self = basename($_SERVER['SCRIPT_NAME']);
$submit = isset($_POST['submit']) ? $_POST['submit'] : null;
$path = '../doc'; // there should be doc directory in your account
$s = 'CHECKED';
define('EOL', "\n");
$choice = '';
if (isset($_POST['choice']))
{
$choice = basename($_POST['choice']);
}
$fpath = $path . '/' . $choice;
$file_choice = $choice;
?>
<?php include('includes/header.php'); ?>
<h1>
Current files online
</h1>
<form action="<?php echo($self); ?>" method="post">
<div class="dir">
<?php
$html = array();
// discover all the files in this directory (i.e., $path)
$html = searchDir($path);
if ($html == null)
{
echo("<p>No files in Directory</p>");
}
else
{
sort($html); // sort the files based upon name
?>
<fieldset>
<legend>Files online</legend>
<label for="choice">Files</label>
<br>
<?php
foreach ($html as $value) // show all the file discovered
{
?>
<input type="radio"
id="choice"
name="choice"
value="<?php echo($value); ?>"
<?php if ($choice == $value)
{
echo($s);
}
?> >
<?php echo($value); ?>
<br>
<?php
}
}
?>
</div>
<p>
<input type="submit" name="submit" value="Choose File">
</p>
</form>
</fieldset>
<?php
if ($choice)
{
echo("<br>File: $choice <br>");
$img = $choice;
$choice = $path . '/' . $choice;
$a = filesize($choice);
echo("File size: $a Bytes <br>");
$unix_in = fileatime($choice);
$a = date("m-d-Y h:i:s", $unix_in);
echo("File last accessed: $a<br>");
$unix_in = filectime($choice);
$a = date("m-d-Y h:i:s", $unix_in);
echo("File last changed: $a<br>");
$unix_in = filemtime($choice);
$a = date("m-d-Y h:i:s", $unix_in);
echo("File last modified: $a<br>");
$a = fileinode($choice);
echo("File Node: $a<br>");
$a = filegroup($choice);
echo("File Group: $a<br>");
$a = fileowner($choice);
echo("File Owner: $a<br>");
$a = filetype($choice);
echo("File Type: $a<br><br>");
if (@getimagesize($choice))
{
echo("<img src=\"../doc/$img\" ><br><br>");
}
echo('<a href="http://www.asciitable.com/"> ASCII TABLE </a><br><br>');
$b = array();
$b = stat($choice);
echo("File Stats:<br><pre>");
print_r(array_slice($b, 13));
echo("</pre>");
$a = findPerms($choice);
echo("Perms (file): $a<br>");
echo substr(sprintf('%o', fileperms($choice)), -4);
echo('<br><br>');
$a = findPerms($path);
echo("Perms (dir): $a<br>");
echo substr(sprintf('%o', fileperms($path)), -4);
echo('<br><br>');
echo('<a href="../permissions.php"> PERMISSION TABLE </a><br><br>');
// following code was provided by William R. Chase
echo '<fieldset class="full"><legend> Hex View </legend>' . EOL;
echo '<table class="hex full">' . EOL;
echo '<tr><td>File: ' . $file_choice . '</td></tr>' . EOL;
echo '<tr><td>' . EOL;
echo '<div class="hex" >' . EOL;
echo ' ';
$ViewWidth = 16;
$ViewHeight = 32;
// print 00-FF
$x = 0;
while ($x < $ViewWidth)
{
echo sprintf('%02X', $x) . ' ';
$x++;
}
echo "\n";
echo ' ';
// print "----------------------------"
$x = 0;
while ($x < $ViewWidth)
{
echo '---';
$x++;
}
echo "\n";
$content = '';
$content = file_get_contents($fpath);
$len = strlen($content);
$h = $ViewHeight;
$x = 0;
$i = 0;
// print content
while ($h > 0)
{
// print start of row
echo sprintf('%04X', $x) . '| ';
$x += $ViewWidth;
$vtext = '';
$count = 0;
// print data in row left
$w = $ViewWidth;
while ($w > 0 && $i < $len)
{
$c = $content[$i];
$vtext .= htmlentities($c);
$c = ord($c);
echo(sprintf('%02X', $c));
echo(' ');
$i++;
$w--;
$count++;
}
// print ASCII in row right
$vtext = str_replace("\n", "", $vtext); // remove unwanted new-lines tedd
// echo str_pad($input, 10, "-=", STR_PAD_LEFT); // produces "-=-=-Alien"
$numNeeded = 16 - $count;
if ($numNeeded > $count)
{
echo(str_pad($vtext, $numNeeded, ' AAAA ', STR_PAD_LEFT));
}
else
{
echo (' ' . $vtext);
}
echo "\n";
$h--;
}
echo '<br>';
echo "\n";
echo '</div>' . EOL;
echo '</td></tr>' . EOL;
echo '</table>' . EOL;
echo '</fieldset>' . EOL;
echo '<br>';
echo '<div class="clear"> </div>' . EOL;
}
include('includes/footer.php');
//==================== functions ======================
//==================== search directory function ======================
// This function returns a listing of all the files in a directory AND all files included
// within other directories within that directory (i.e., drills down)
function searchDir($path)
{
$files = array(); // create a files array
$dir = opendir($path) or die("Can't find file"); //open directory
// browse all files and folders in the directory
while (false !== ($item = readdir($dir)))
{
if ($item == '.' | $item == '..')
{
continue;
}
if ($item != 'index.php') // exclude the index.php file from listing
{
$item = $path . '/' . $item;
// if the item is a directory, then drill down using a recursive call to this function
if (is_dir($item) && $item != '.' && $item != '..')
{
$f = searchDir($item); // a recursive call to this function (return an array)
$files = array_merge($files, $f); // merge the arrays
}
if (!is_dir($item)) // exclude directories from being includes
{
$files[] = $item; // put files in the array (i.e., build the array)
}
}
}
closedir($dir); // close directory
return $files; // return the files array
}
//-----------
function findPerms($choice) // this returns the permissions of a file/dir
{
$perms = fileperms($choice);
if (($perms & 0xC000) == 0xC000)
{
// Socket
$info = 'Socket: ';
}
else if (($perms & 0xA000) == 0xA000)
{
// Symbolic Link
$info = 'Link: ';
}
else if (($perms & 0x8000) == 0x8000)
{
// Regular
$info = 'File: ';
}
else if (($perms & 0x6000) == 0x6000)
{
// Block special
$info = 'Block: ';
}
else if (($perms & 0x4000) == 0x4000)
{
// Directory
$info = 'Directory: ';
}
else if (($perms & 0x2000) == 0x2000)
{
// Character special
$info = 'Character: ';
}
else if (($perms & 0x1000) == 0x1000)
{
// FIFO pipe
$info = 'Pipe: ';
}
else
{
// Unknown
$info = 'Unknown: ';
}
// Owner
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x') :
(($perms & 0x0800) ? 'S' : '-'));
$info .= " ";
// Group
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x') :
(($perms & 0x0400) ? 'S' : '-'));
$info .= " ";
// World
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x') :
(($perms & 0x0200) ? 'T' : '-'));
return $info;
}
?>