how to create an advanced open dir code in php?

  • Thread starter Thread starter scopefragger
  • Start date Start date
S

scopefragger

Guest
ok, ready guys because this is a big one.
Because of the structure of the project I'm currently using i require to use the OPENDIR command in php to show the contents of a specific directory. I also require the list to be in order of newest to oldest as well as hiding specific files.

Now I have a code that will do this and will show the directory in the order is wish however i cant manipulate the code correctly to get it so that i can hide specific files. and more importantly i need to hide file extensions. Here is what i have

<?
function comparar($a, $b)
{
return strnatcasecmp($b["1"], $a["1"]); //reversed to order from newest to oldest, change to ($a["1"], $b["1"]) to do oldest to newest
}
$default_dir = "."; //current directory
$dirlist = array(); //make new array
$dir = dir($default_dir);
while($file = $dir->read()) //read directory
{
if(0 != strpos($file, '.php')) //if filename has .demo in it continue
{
$lastmodified = filemtime($file); //find filetime in milliseconds
$dirlist[] = array($file, $lastmodified); //put these into array
}
}
$dir->close();
usort($dirlist, "comparar"); //send array to usort
$arraynum = sizeof($dirlist); //how many entities the array contains
$i = 0;
while($i < $arraynum)
{
$curList = $dirlist[$i]; //set current array to access
$curFile = $curList[0]; //access that array's first array
$curTime = $curList[1]; //access that array's second array
$curDate = date("m/d/y", $curTime); //convert time into something readable
if ($file != "." && $file != ".." && $file != "showall.php")
{
echo "<br>$curFile";
$i = $i + 1; //next $i
}
}
?>
 
Back
Top