Jump to content

[SOLVED] Display Files in Folder - Folders displayed as Bold?


Recommended Posts

I found this script to display all files in a folder and display them as a link. So far I love it but I would like to be able to echo Folders/directories as a Bold line. I've added a switch for filtering out index.php or other files I dont want displayed. How can I check to see if $narray is a Folder or Directory?

 

Here is the full code.

<?php
$path = "./";
$narray=array();
$dir_handle = @opendir($path) or die("Unable to open $path");
echo "Directory Listing of $path<br/>";
$i=0;
while($file = readdir($dir_handle))
{
     if($file != '.' && $file != '..')
    {
        //echo "<a href='$path/$file'>$file</a><br/>";
        $narray[$i]=$file;
        $i++;
    }
}
sort($narray);

for($i=0; $i<sizeof($narray); $i++)
{
$dirname = $narray[$i];

switch ($narray[$i])
{
case "index.php":
  echo "<br />";
  break;
case 2:
  echo "Number 2";
  break;
case 3:
  echo "Number 3";
  break;
default:
  echo "<a href=".chr(34).$path.$narray[$i].chr(34).">".$narray[$i]."</a><br/>";
}



}

//closing the directory
closedir($dir_handle);
?>

I found the solution (below is the script). I will post another question on how to have select links certain colors without using css.

<?php
$path = "./";
$narray=array();
$dir_handle = @opendir($path) or die("Unable to open $path");
echo "Directory Listing of $path<br/>";
$i=0;
while($file = readdir($dir_handle))
{
     if($file != '.' && $file != '..')
    {
        //echo "<a href='$path/$file'>$file</a><br/>";
        $narray[$i]=$file;
        $i++;
    }
}


sort($narray);

for($i=0; $i<sizeof($narray); $i++)
{
$dirname = $narray[$i];

switch ($narray[$i])
{
case "index.php":
  echo "<br />";
  break;
case 2:
  echo "Unused";
  break;
case 3:
  echo "Unused";
  break;
default:
$checkfile = $narray[$i]; 
if (!is_file($checkfile)) 
//Although adding the Color, the link color (blue) is still the printed link color.
echo "<font color='GREEN'>"."<B>"."<a href=".chr(34).$path.$narray[$i].chr(34).">".$narray[$i]."</a>"."</b><br/></font>"  ;
//Commenting the above echo and uncommenting the below echo tells me that the link properties overrides the font commands for that line.
//echo "<font color='GREEN'>"."<B>".$narray[$i]."</b><br/></font>";  
  else echo "<a href=".chr(34).$path.$narray[$i].chr(34).">".$narray[$i]."</a><br/>";
  
}



}

//closing the directory
closedir($dir_handle);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.