Jump to content

List folders and files


KingOfHeart

Recommended Posts

All you have to do is turn this into a function and add the file info.

It also display icons of the file type. I've attached them just in case.

 

<style>
a {
color:blue;
font-size:10pt;
text-decoration:none;
font-weight:400;
font-family:verdana, arial, helvetica, sans-serif;
padding:0px 0px 0px 0px;
}
a:visited {color:#4020e0;}
a:hover {color:blue;font-weight:400;}
a:active {color:yellow;}
</style>

<table width="100%"><tr><td colspan=3 align=center>
<?php
$dir    = '/home';
echo "<h3>Index of $dir</h3>"
?>

</td><tr><td width="25%"></td><td valign="top">

<?php
$arraydir=array();
$arrayfile=array();

$files = scandir($dir);
natcasesort($files);
//$files=natsort($files);
foreach ($files as $file)
{
    if ($file != "." && $file != "..")
    {
        if(is_dir($file))
        {
         array_push($arraydir,$file);
        }
        else
        {
        array_push($arrayfile,$file);
        }
    }
}

echo "files<br>";
foreach($arrayfile as $file)
{
  list($xxx,$ext)=explode(".",$file);
  trim($ext);
   echo "<img src=\"./images/$ext.png\" /><a href=\"$file\">$file</a><br>\n";
}

echo "<P>";
echo "</td><td valign=\"top\">directories<br>";
foreach($arraydir as $file )
{
echo "<img src=\"./images/folder.png\" border=0><a href=\"$file\">$file</a><br>\n";
}

//print_r($files);
?>

</td></tr></table>

 

 

HTH

Teamatomic

 

[attachment deleted by admin]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.