TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 05-24-2009, 07:59 AM   #1 (permalink)
The Acquainted
 
Peuplarchie's Avatar
 
Join Date: May 2008
Location: Québec
Posts: 104
Thanks: 10
Peuplarchie is on a distinguished road
Application 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 !
__________________
That's why we are not alone on earth... let's build !
Peuplarchie is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual Directory Support? delayedinsanity General 4 11-08-2012 09:04 PM
Next class project? allworknoplay The Lounge 6 04-18-2009 08:33 PM
[How To] Allow / Disallow Directory Browsing dynaweb Tips & Tricks 6 04-14-2009 12:57 PM
Fix recursive function on a directory listing Peuplarchie General 1 04-13-2009 03:04 AM
Creating directory hierarchies with ease Wildhoney Script Giveaway 3 12-04-2008 02:28 AM


All times are GMT. The time now is 07:39 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design