Thread: Snippet: Dynamic directory listing

Results 1 to 2 of 2
  1. #1 Snippet: Dynamic directory listing 
    Registered Member Spida's Avatar
    Join Date
    Sep 2007
    Age
    24
    Posts
    368
    Thanks given
    13
    Thanks received
    23
    Rep Power
    4
    This isn't a tutorial, it's just a snippet that displays all the directories in your current directory. Includes a blacklist of directories you don't want to be listed..


    An example index that runs through and links to all my projects
    Code:
    <?php
    $array = glob('*/'); //fetch all directories
    
    $blacklist = array('cgi-bin/'); //directories you don't want in the array
    
    foreach ($array as $key => $value) {
    	if (in_array($value, $blacklist)) {
    		unset($array[$key]); //remove blacklisted item from the glob array
    	}
    }
    ?>
    <!DOCTYPE html>
    <html>
    <head>
    	<title>Project Portal</title>
    </head>
    <body>
    You can access my projects that are on the following list:
    <ul>
    	<?php
    	foreach ($array as $item) {
    		$cleanedItem = substr($item, 0, -1);
    		echo "<li><a href='{$cleanedItem}'>", ucfirst($cleanedItem), "</a></li>";
    	}
    	?>
    </ul>
    </body>
    </html>
    Reply With Quote  
     

  2. #2  
    Adobe

    Dreamweaver's Avatar
    Join Date
    Jan 2010
    Posts
    1,067
    Thanks given
    38
    Thanks received
    149
    Rep Power
    246
    Good work, try your fixing your tabbing to make it look better.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 05-18-2012, 10:32 AM
  2. Replies: 2
    Last Post: 04-10-2012, 09:42 AM
  3. [Java] Listing Primes [Java]
    By Intel! in forum Homework
    Replies: 4
    Last Post: 12-21-2011, 04:54 PM
  4. Model anInt165 directory and anInt200 Directory
    By RSTrials in forum RS2 Client
    Replies: 1
    Last Post: 06-14-2010, 11:08 PM
  5. Player listing help
    By Seth1 in forum Projects
    Replies: 0
    Last Post: 11-27-2008, 12:35 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •