Dustin013 Posted July 10, 2008 Share Posted July 10, 2008 I am using a scan directory script I found. What I am trying to do is put all the folder names ($file) that are scanned into an array so that I can run the code again in a loop for each $file in the array. I can't seem to get it right. Any suggestions? <?php function getDirectory( $path = '.', $level = 0 ){ $ignore = array( 'cgi-bin', '.', '..' ); // Directories to ignore when listing output. Many hosts // will deny PHP access to the cgi-bin. $dh = @opendir( $path ); // Open the directory to the handle $dh while( false !== ( $file = readdir( $dh ) ) ){ // Loop through the directory if( !in_array( $file, $ignore ) ){ // Check that this file is not to be ignored $spaces = str_repeat( ' ', ( $level * 4 ) ); // Just to add spacing to the list, to better // show the directory tree. if( is_dir( "$path/$file" ) ){ // Its a directory,print title... //I NEED THIS TO PLACE $file INTO AN ARRAY echo "<strong>$file</strong><br />"; } } } closedir( $dh ); // Close the directory handle } getDirectory("."); ?> Link to comment https://forums.phpfreaks.com/topic/114006-how-do-i-put-this-into-an-array/ Share on other sites More sharing options...
trq Posted July 10, 2008 Share Posted July 10, 2008 Replace... echo "<strong>$file</strong><br />"; with $files[] = $file; You now have an array called $files containing all your files. Link to comment https://forums.phpfreaks.com/topic/114006-how-do-i-put-this-into-an-array/#findComment-585935 Share on other sites More sharing options...
trq Posted July 10, 2008 Share Posted July 10, 2008 Of course, it would be easier to simply use scandir(). Link to comment https://forums.phpfreaks.com/topic/114006-how-do-i-put-this-into-an-array/#findComment-585938 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.