/ Published in: PHP

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php function dir_recursive($path, $parent = ''){ while (false !== ($entry = $d->read())) { if($entry == '.' || $entry == '..') continue; //if this is a directory, loop inside its contents //if parent dir given, then create another array dimension to be used to store files under this parent $files[$parent][$entry] = dir_recursive($d->path.'/'.$entry, $entry); }else $files[$entry] = dir_recursive($d->path.'/'.$entry, $entry); }else $files[$entry] = $entry; //reset parent dir given, so it won't create another array dimension for the next loop of subdirectory $parent = ''; } $d->close(); return $files; } //usage $files = dir_recursive('.'); ?>
Comments
