JMair Posted August 13, 2009 Share Posted August 13, 2009 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); ?> Link to comment https://forums.phpfreaks.com/topic/170134-solved-display-files-in-folder-folders-displayed-as-bold/ Share on other sites More sharing options...
JMair Posted August 13, 2009 Author Share Posted August 13, 2009 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); ?> Link to comment https://forums.phpfreaks.com/topic/170134-solved-display-files-in-folder-folders-displayed-as-bold/#findComment-897487 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.