Skip to content

Instantly share code, notes, and snippets.

@AdamZWinter
Created June 7, 2020 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamZWinter/698cbcdb6bcf7f4a7e13003a07e2cae0 to your computer and use it in GitHub Desktop.
Save AdamZWinter/698cbcdb6bcf7f4a7e13003a07e2cae0 to your computer and use it in GitHub Desktop.
<?php
echo '
<table width=50%>
<thead>
<tr>
<th width=60%><p>Name</p></th>
<th width=20%><p>Owner</p></th>
<th width=20%><p>Permission</p></th>
</tr>
</thead>
<tbody>
';
$cwd = getcwd();
if(isset($_GET['dir'])) {
$cwd = $_GET['dir'];
}
$fil = scandir($cwd);
foreach ($fil as $file) {
$path = realpath($file);
$dir = '/'.$file;
echo '<tr>';
if($file == '..'){
$parent = dirname($cwd);
echo '<td><a href=" '.$_SERVER['PHP_SELF'].'?dir='.$parent.' ">'.$file.'</a></td>';
echo '<td><p>'.posix_getpwuid(fileowner($file))["name"].'</p></td>';
echo '<td><p>'.substr(sprintf('%o', fileperms($file)), -3).'</p></td>';
}
elseif($file == '.') {
//do nothing
}
elseif(is_dir($cwd.'/'.$file)) {
echo '<td><a href=" '.$_SERVER['PHP_SELF'].'?dir='.$cwd.'/'.$file.' ">'.$cwd.'/'.$file.'</a></td>';
echo '<td><p>'.posix_getpwuid(fileowner($cwd.'/'.$file))["name"].'</p></td>';
echo '<td><p>'.substr(sprintf('%o', fileperms($cwd.'/'.$file)), -3).'</p></td>';
}
else {
echo '<td><a href="https://'.$_SERVER['SERVER_NAME'].'/utilities/editor.php?edit='.$cwd.'/'.$file.' " target="_blank">'.$file.'</a></td>';
echo '<td><p>'.posix_getpwuid(fileowner($cwd.'/'.$file))["name"].'</p></td>';
echo '<td><p>'.substr(sprintf('%o', fileperms($cwd.'/'.$file)), -3).'</p></td>';
}
echo '<tr>';
}
echo '</tbody></table>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment