Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get recursive filename and stored it into array in php
    primarykey
    data
    text
    <p>I have a function getting the recursive folder's filename inside a specific path:</p> <pre><code>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 $files_matched = array(); while( false !== ( $file = readdir( $dh ) ) ){ // Loop through the directory if( !in_array($file, $ignore ) &amp;&amp; !preg_match("/^.*\.(rar|txt)$/", $file) ){ // Check that this file is not to be ignored if( is_dir( "$path/$file" ) ){ // Its a directory, so we need to keep reading down... echo "&lt;strong&gt;$spaces $file&lt;/strong&gt;&lt;br /&gt;"; getDirectory( "$path/$file", ($level+1) ); // Re-call this same function but on a new directory. // this is what makes function recursive. } else { $files_matched[$i] = $file; $i++; } } } closedir( $dh ); // Close the directory handle return $files_matched; } echo "&lt;pre&gt;"; $files = getDirectory("F:\Test"); foreach($files as $file) printf("%s&lt;br /&gt;", $file); echo "&lt;/pre&gt;"; </code></pre> <p>I used $files_matched to stored the filename in an array.</p> <p>And for the above result, it only display the filename under "F:\test". </p> <p>Actually, I have a sub-folder under "F:\test". How can I display those filename using the array for storage?</p> <p>If I modified the code:</p> <pre><code>$files_matched[$i] = $file; $i++; </code></pre> <p>into:</p> <pre><code>echo "$files&lt;br /&gt;"; </code></pre> <p>This will be worked fine and I just don't know why use array to store the filename for later process is not work??</p> <p>Thanks for help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload