File Lister(with properties)

By Gex on Apr 16, 2007

This code allows u to call the function which is listfiles(); from anywhere from the script and list the files in the directory of the script and sort them in a table with their properties.

<?php
function listfiles() {
$cdir = getcwd();
$contents =  scandir($cdir);
$num = count($contents);
$x = 0;
echo  "<body align=\"center\"><table style=\"text-align: left; width: 700; height: 31px;\"
 border=\"0\" cellpadding=\"2\" cellspacing=\"10\">
 <tbody>
    <tr >
     <td style=\"background-color: rgb(51, 51, 51);\"><span
 style=\"color: rgb(204, 204, 204);\">
Filename</td></span>
      <td bgcolor=\"grey\"><span
 style=\"color: rgb(255, 255, 255);\">Size</td></span
      <td bgcolor=\"grey\"><span
 style=\"color: rgb(255, 255, 255);\">Perms</td></span>
    <td bgcolor=\"grey\"><span
 style=\"color: rgb(255, 255, 255);\">Stats</td></span>
    <td bgcolor=\"grey\"><span
 style=\"color: rgb(255, 255, 255);\">IsExec</td></span>
    <td bgcolor=\"grey\" ><span
 style=\"color: rgb(255, 255, 255);\">Readable</td></span>
     <td bgcolor=\"grey\" ><span
 style=\"color: rgb(255, 255, 255);\">Writeable</td></span>
    </tr><tr></tr>";
while ($num >= $x) {
if (file_exists($contents[$x])  && $contents[$x] != "."  &&  $contents[$x] != "..") {
echo "
    <tr>
    <td><a href=".$contents[$x].">".$contents[$x]."</a>"."<br></td>
        <td>".(filesize($contents[$x])/1000)." KB</td>
    <td><font color=\"blue\">".substr(sprintf("%o",fileperms($contents[$x])),-4)."</font></td>
    <td>".stat($contents[$x])."</td>
";
    if (is_executable($contents[$x])) {
    echo "<td><font color=\"green\">Yes</font></td>    ";
    } else {
    echo "<td><font color=\"red\">No</font></td>    ";
    if (is_readable($contents[$x])) {
    echo "<td><font color=\"green\">Yes</font></td>    ";
    } else {
    echo "<td><font color=\"red\">No</font></td>    ";
    }
       if (is_writeable($contents[$x])) {
    echo "<td><font color=\"green\">Yes</font></td> </tr>   ";
    } else {
    echo "<td><font color=\"red\">No</font></td> </tr>   ";
    }

    }
}
$x++;
}
 echo " </tbody></tr>
</table></body>";
}
listfiles();
?>

Comments

Sign in to comment.
Undefined_Variable   -  Mar 08, 2008

Very nice!

 Respond  
Gex   -  Apr 17, 2007

yep..ima work on that ;)

 Respond  
Hawkee   -  Apr 17, 2007

Would be nicer if you eliminated all the HTML and replaced it with div\'s and CSS.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.