WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Dump the contents of a PHP variable in html format with a recursive list of subfolders and files from a given root directory.
Categories : PHP, Directories, Variables, Arrays Click here to Update Your Picture
aitor solozabal merino
Date : Aug 28th 2007
Grade : 3 of 5 (graded 2 times)
Viewed : 4414
File : 4695.php
Images : No Images for this code example.
Search : More code by aitor solozabal merino
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 


<?php
/*
=============================================================================
Name Program : scandir_list_array_dump.php
Author       : Aitor Solozabal Merino (Spain)
Email        : aitor-3@euskalnet.net
Date         : 25-08-2007
Type         : php program code utility
Description  : A dump in html format of the contents of one variable with a
              : recursive list of subfolders and files from a given root directory
Installation : Put this programs in a subfolder of the www of your web server
              : document root directory

              There are two outputs of the html
              1 - with simple html commands
              2 - using html table with cells with nested tables recursively
*/
function scandir_list_array_dump($SCAN_DIRECTORY, $DEEP_LEVEL = 0, $DIRECTORY_LIST = "")
{
    if (
is_array($DIRECTORY_LIST)) {
       
$output .= basename($SCAN_DIRECTORY) . "<br>";
        foreach (
$DIRECTORY_LIST as $key => $value) {
            if ((
$value <> '.') and ($value <> '..')) {
                if (
is_dir($SCAN_DIRECTORY . "/" . $value)) {
                    for (
$i = $DEEP_LEVEL-1;$i > 0;$i--) {
                       
$output .= " " . " " . "|" . " ";
                    }
                   
$output .= " " . "+". " ";
                } else {
                    for (
$i = $DEEP_LEVEL-1;$i > 0;$i--) {
                       
$output .= " " . " " . "|" . " ";
                    }
                   
$output .= " " . " " . "|_ ";
                }

               
$value = scandir_list_array_dump($SCAN_DIRECTORY, $DEEP_LEVEL, $value);
               
$output .= $value;
            }
        }
        return
$output;
    } else {
       
$SCAN_DIRECTORY .= "/" . $DIRECTORY_LIST;
        if (
is_dir($SCAN_DIRECTORY)) {
           
$DEEP_LEVEL = $DEEP_LEVEL + 1;
            return
scandir_list_array_dump($SCAN_DIRECTORY, $DEEP_LEVEL, SCANDIR($SCAN_DIRECTORY));
        } else {
            return
$DIRECTORY_LIST . "<br>"; //nombre fichero
       
}
    }
}
function
scandir_list_array_dump2($SCAN_DIRECTORY, $DEEP_LEVEL = 0, $DIRECTORY_LIST = "")
{
    if (
is_array($DIRECTORY_LIST)) {
       
$output = "<table border='1'>";
       
$output .= "<head><tr><td><b>" . basename($SCAN_DIRECTORY) . "</b></td></tr></head>";
       
$output .= "</table>";
       
$output .= "<table border='1'>";
       
$output .= "<body>";
        foreach (
$DIRECTORY_LIST as $key => $value) {
            if ((
$value <> '.') and ($value <> '..')) {
               
$output .= "<tr valign='TOP'><td></td><td valign='TOP'>";
                if (
is_dir($SCAN_DIRECTORY . "/" . $value)) {
                   
$output .= "D</td>";
                } else {
                   
$output .= "F</td>";
                }
               
$value = scandir_list_array_dump2($SCAN_DIRECTORY, $DEEP_LEVEL, $value);
               
$output .= "<td valign='TOP'>$value</td></tr>";
            }
        }
       
$output .= "</body></table>";
        return
$output;
    } else {
       
$SCAN_DIRECTORY .= "/" . $DIRECTORY_LIST;
        if (
is_dir($SCAN_DIRECTORY)) {
           
$DEEP_LEVEL = $DEEP_LEVEL + 1;
            return
scandir_list_array_dump2($SCAN_DIRECTORY, $DEEP_LEVEL, SCANDIR($SCAN_DIRECTORY));
        } else {
            return
strval($DIRECTORY_LIST);
        }
    }
}

echo
scandir_list_array_dump($_SERVER['DOCUMENT_ROOT']);
// or you can use the second dump
//echo scandir_list_array_dump2($_SERVER['DOCUMENT_ROOT']);



/*
This program code is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation in any version
of the License.
This program is non professional and distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
?>



Display list of files within current and subdirectories (recursively) showing each file as an anchored link and each directory as a category header.
Categories : Filesystem, Directories, Arrays, PHP
PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside.
Categories : PHP, Arrays, Variables
A database abstraction layer for the PHP Oracle 8 module (available from PHP 3.0.5). It supports persistent connections, fetching rows into arrays, prepare/execute (variable binding) and has a new and improved error interface.
Categories : Databases, Oracle, PHP, Arrays, Variables
Variable serialization and unserialization. Loading and saving variable structures to and from file.
Categories : Arrays, Filesystem, Variables, Strings, PHP
Simple script to passing persistent and growing array between recalls of one page (manipulate little stack).
Categories : Arrays, Global Variables, PHP, HTML and PHP, Variables
translate.php - Assocciative array example, passing a reference to a function.
Categories : PHP, Arrays, Languages, Variables
clearing variables in php3
Categories : Variables, Arrays, PHP
A class to put get and post variables in hidden form elements. Works on scalars, normal arrays, associative arrays.
Categories : Algorithms, Variables, Arrays, PHP, PHP Classes
How to pass an array to a function, or how to define a function wich recieves an array.
Categories : Variables, PHP, Arrays
Pageinfo: Array containing page URI, page query string (parameters), request method (GET or POST) and the complete URI
Categories : Variables, PHP Options and Info, Arrays, URLs, PHP
A function which places the path and name of all subdirectories into an array
Categories : PHP, Filesystem, Arrays, Directories
PHP4 DirectoryIterator Class
Categories : PHP, PHP Classes, Filesystem, Directories
serialize -- Generates a storable representation of a value
Categories : PHP, PHP Functions, Variables
PHP Random rss feeds - selects 49 random feeds from an unlimited list and displays them on your website. It's Ideal for those moments when you got 5 minutes and dont know which one of your feeds to read.
Categories : PHP, Rich Site Summary (RSS), Arrays
Looping through two arrays
Categories : PHP, Databases, Arrays
 aitor solozabal merino wrote :1701
It is very easy to put into practice, in the second chance of the function, 
a better graphical html output and/or an good user interface replacing the 
lettering D and F for images of a folder and a file with links to choose.
If you doesn´t like the cell`s border of the table put 0 instead of the 
1 in the line of code.

<?
$output 
.= "<table border=`1`>"
?>