Jump to content

HTML With PHP


Mod-Jay

Recommended Posts

Okay i want line 18's DIV to actually not end on each repeat. im getting confused on how to do it. but everything i try it doesnt work.

1 <?php
2 function getDirectory( $path = '../toplist/', $level = 3 ){ 
3
4     $ignore = array( 'cgi-bin', '.', '..', 'images', 'js', 'css', 'admin'); 
5     $dh = @opendir( $path ); 
6      
7     while( false !== ( $file = readdir( $dh ) ) ){ 
8      //$files = "<div class=\"msg_body\"><a href='edit.php?file=$file'>". $file ."</a> ";
9         if( !in_array( $file, $ignore ) ){ 
10              
11             $spaces = str_repeat( ' ', ( $level * 4 ) ); 
12             if( is_dir( "$path/$file" ) ){ 
13                 echo "<p class=\"msg_head\"><strong>$spaces - $file</strong></p>";
14 // 			    echo "<strong>$spaces - $file<br /></strong>";
15                 getDirectory( "$path/$file", ($level+1) ); 
16             } else { 
17              
18                echo "<div class=\"msg_body\">$spaces $file<br /></div>"; 
19 //				  echo "$spaces $file<br />";
20 				} 
21 
22 				}
23 		
24    } 
25     closedir( $dh );
26 
27 }
29 ?> 

Link to comment
Share on other sites

Is this what you're looking for?  Or does it need to go outside the while statement?

function getDirectory( $path = '../toplist/', $level = 3 ){ 
$ignore = array( 'cgi-bin', '.', '..', 'images', 'js', 'css', 'admin'); 
$dh = @opendir( $path );
while( false !== ( $file = readdir( $dh ) ) ){ 
if( !in_array( $file, $ignore ) ){ 
$spaces = str_repeat( ' ', ( $level * 4 ) );
echo "<div class=\"msg_body\">"; 
if( is_dir( "$path/$file" ) ){ 
echo "<p class=\"msg_head\"><strong>$spaces - $file</strong></p>";
echo "<strong>$spaces - $file<br /></strong>";
getDirectory( "$path/$file", ($level+1) ); 
} else { 
echo "$spaces $file<br />"; 
}//End ELSE	
echo "</div>";
}//END if( is_dir( "$path/$file" )
}//End while( 
closedir( $dh );
}

Link to comment
Share on other sites

is this going to be building a bunch of div's inside of divs? if you don't end the div everytime thats what your ending up with.

I agree.  Those div's should be outside the while statement.  I just moved it out of the IF ELSE statements as he requested.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.