ok, here you are, you have a directory of files and some child directories and you want to be able to get the values of those files and directories and put them in a string. but how can you do that? well, i have the answer for you. if you want to get a list of files and display them on your browser you can use this php code i have here for you. i have this wallpaper website and i wanted to get the values of each file. for example, lets says i have this dirctory in my website called includes and in the includes/ directory i have these files and directories:

images/
classes/
dbconnection.php
functions.php
contstants.php

now, would it be cool if i could just show a list in my browser of the files and not the direcotries, or vise versa,, i only want to display the directories and not the files, well, its simple. let me show you want you can do:

1. step one is open your favorite text editor. im using windows xp so i will be using notepad.
2. copy and paste the code below and save the file as index.php and put it in the directory where you want the list of the files.
3. open the index.php file with your browser, then it will show you a list of the files.

this php code will show the files in a directory, but you can also use it to show you the path of the files and folder. you can also use it to get a list of directories and display them. or if you have a folder or images, you can use it so show the current directory in that folder. note that folder and directory are the same thing, folders are used in windows, and directories are used in unix systems. but with php you can use to include directories and show the server path so it dont matter what kind of platform you are using. they both display a directory listing. i hope i have showed you wow to display directory tree using php, its very simple, really to display contents of a folder with php right?

NOTE: the code below shows only the directories, but if you want to only show the files and not the directories, then change

from:
if (!strstr($file,'.')){

to:
if (strstr($file,'.')){


ok, how about if you want to show all of the files and directories, then just remove lines 5 and 7 from the example code below.
Line 5: if (!strstr($file,'.')){
Line 7: }




CODE

<?php
 if ($handle = opendir('.')) {
   while (false !== ($file = readdir($handle))){
   		if ($file != "." && $file != ".."){
       		if (!strstr($file,'.')){
				$IndexList .= '<a href="'.$file.'">'.$file.'</a><br>';
			}
    	}
  	}
  closedir($handle);
  }
?>
<P>List of files:</p>
<P><? print_r($IndexList); ?></p>