Jump to content

How do I put this into an Array?


Dustin013

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.