0

HERE IS MY CODE. I NEED TO OPEN EACH DIRECTORY AND MAKE THE LINKS FOR EACH SUBDIRECTORY. THE PROBLEM IN THIS CODE IS: EACH DIRECTORY HAS THE SAME FILE AS IN THE PREVIOUS ONE.. LIKE FOR EXAMPLE, WEBSITE OUTPUTS:

DIRECTORY1
FILE1
----
DIRECTORY2
FILE1
FILE2
----
DIRECTORY3
FILE1
FILE2
FILE3
----
AND SO ON.... WHAT WRONG AM I DOING. DIRECTORY CLOSES EVERY LOOP.. PLEASE HELP, THIS IS THE CHURCH PROJECT, SO PEOPLE CAN DOWNLOAD CHURCH RECORDINGS...

-----------------------------------------------------------------------------------------
<?php
$dir1 = opendir('../downloads/BBC_Recordings/');

while ($read1 = readdir($dir1)) {
if ($read1!='.' && $read1!='..'){

?>
<div class="container_in">
<h2 class="trigger_in"><h_pan_in><?php echo $read1; ?></h_pan_in></h2>
<div class="toggle_container_in">
<div class="block_in">

<?php
//show files
$myDirectory1 = opendir("../downloads/BBC_Recordings/$read1/");
while($entryName1 = readdir($myDirectory1)) { $dirArray1[] = $entryName1; }
closedir($myDirectory1);
$indexCount1 = count($dirArray1);
sort($dirArray1);
print("<TABLE width='100%' border=0 cellpadding=5 cellspacing=0 class='zebra'>\n");
print("<TR><th></th></TR>\n");
for($index1=0; $index1 < $indexCount1; $index1++) {
if (substr("$dirArray1[$index1]", 0, 1) != "."){
print("<TR><TD><a href=\"../downloads/BBC_Recordings/$read1/$dirArray1[$index1]\" target=\"_blank\">$dirArray1[$index1]</a></td>");
print("</TR> ");

}}
print("</TABLE>\n");
//
?>

</div>
</div>
</div>
<?php
}}
closedir($dir1);
?>


-----------------------------------------------------------------------------------------

Edited by yuryla: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by theausum
0

well, does this helps you ? ->

/**
 * Reads the directory path specified in the first parameter 
 * and builds an array representation of it and all its 
 * contained files. if $top_level_only is set to TRUE then the 
 * sub-folders wont be mapped. if $hidden is set to TRUE then 
 * the hidden files and folders will also be mapped
 *
 * @access	public
 * @param	string
 * @param	bool
 * @param	bool
 * @return	array
 */
 function mapDir($source_dir, $top_level_only = FALSE, $hidden = FALSE){
	//create a directory handler/resource that can be used to readdir(), closedir() or rewinddir()
	if ($fp = opendir($source_dir)){
		//trim all the trailing / (for linux and unix) and \ (for windows) and then add / . / added by php works for windows :)
		$source_dir = rtrim($source_dir, "/"); $source_dir = rtrim($source_dir, "\\"); $source_dir .= "/";
		//create an array that will store all the contents of the dir
		$filedata = array();
		/*read the dir. readdir() returns the filename of the next file from the directory. !== shud be used since FALSE is boolean(hence, strict type comparison)*/
		while (FALSE !== ($file = readdir($fp))){
			/*file starting with . are hidden. strncmp compares the character in the 2nd param with the character of the 1st param. No. of char to be compared is given by the 3rd param*/
			if (($hidden == FALSE && strncmp($file, '.', 1) == 0) OR ($file == '.' OR $file == '..')) continue;
			if ($top_level_only == FALSE && is_dir($source_dir.$file)){
			$temp_array = array();
			$temp_array = mapDir($source_dir.$file."/", $top_level_only, $hidden);
			$filedata[$file] = $temp_array;
			}
			else $filedata[] = $file;
		}
	//close the handler/resource
	closedir($fp);
	return $filedata;
	}
	//return false if some problem occured while opening the dir
	else return FALSE;
 }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.