TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Listing level of a directory differently... (http://www.talkphp.com/general/4428-listing-level-directory-differently.html)

Peuplarchie 05-24-2009 07:59 AM

Listing level of a directory differently...
 
Good day to you all,
I'm listing a directory, folder only and recurcively.
I'm wondering if :

1) I can display the folders in level 0 of the directory bold instead of as a link.


Here is my code :

PHP Code:



<?php
//Start a session
session_start();

// Error report put at report all
error_reporting(E_ALL);


ini_set("display_errors""on");
        
set_time_limit(0);
        
//Put as variable the directory i start from
$directory "Trips/";

// The dirlist function declarations
function dirList ($directory)
{
 
    
//create 2 arrays - one for folders and one for files
   
$folders = array();
   
$files = array();
 
    
// create a handler for the directory
    
$handler opendir($directory);
 
    
// keep going until all files in directory have been read
while (false !== ($file readdir($handler))) {  
 
        
// if $file isn't this directory or its parent,
        // add it to the results array
        
if ($file != '.' && $file != '..')
       
        
// If file is directory, mark it in bold.

       
if(is_dir($directory.$file)) {
        
array_push($folders,$file);
        
            if (
time() - filemtime($directory.$file) < 604800) { 
// If file is younger than a month, write in red 
    
$folder_modified[] = "<li id=\"folder\"><a href=\"index.html\" onclick=\"load('folder_view.php?dir=".$directory."".$file."','boxdisp');return false;\" style=\"color:#DB1212;\">".$file."</a>";
    
} elseif (
time() - filemtime($directory.$file) < 31556926) { 
// If file is older than a month but younger than a year, write in green 
    
$folder_modified[] = "<li id=\"folder\"><a href=\"index.html\" onclick=\"load('folder_view.php?dir=".$directory."".$file."','boxdisp');return false;\" style=\"color:#00300;\">".$file."</a>";
    
    
// file, folder, older than a year, write it in black
} else {$folder_modified[] = "<li id=\"folder\"><a href=\"index.html\" onclick=\"load('folder_view.php?dir=".$directory."".$file."','boxdisp');return false;\" style=\"color:#000000;\">".$file."</a>";}
 
 
        
// Here I would list the files too but I don't need it for this site.
        // Else not styled
        
}else{
        
array_push($files,$file);
     
$filenamecor substr($file0, -4);
    if (
time() - filemtime($directory.$file) < 604800) {
    
$file_modified[] = '<span style="color:#DB1212;">'.$filenamecor.'<span>';
} elseif (
time() - filemtime($directory.$file) < 31556926) {
    
$file_modified[] = '<span style="color:#003366;">'.$filenamecor.'<span>';
} else {
$file_modified[] = '<span style="color:#000000;">'.$filenamecor.'<span>';}
 
// write nothing cause I don't need the files to be listed .
 
    
}
    }


//declaring the variable that the result will be put in.
$output "";
// starting the list by 
    
$output .= "<ul id=\"".preg_replace('/\//','_',substr($directory,0,strlen($directory)-1))."\">\n"//start a new unordered list for every iteration through dirList
 
$dircor $directory;
    
// tidy up: close the handler
    
closedir($handler);
    foreach(
$folders as $folder=>$file) {
        
      
$output .= "".$folder_modified[$folder]; //echo the folder name enclosed in a list item
      
$output .=   dirList($directory.$file.'/'); //loop through the contents of $folder
      
$output .= "\n"//close this list item after all files and folders in $folder have been looped through
   
   
    
}
 
    foreach(
$files as $key=>$file) {

    }
 
 
    
$output .= "</ul>\n"//close the unordered list

      
return $output;

echo 
$output;

    }

$list dirList ($directory);

Let me know if you need mode information.
Thanks !


All times are GMT. The time now is 04:19 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0