Advertisement
Guest User

Untitled

a guest
Mar 27th, 2023
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | Source Code | 0 0
  1. <?php
  2. function getDirContents($dir, &$results = array()) {
  3.     $files = scandir($dir);
  4.  
  5.     foreach ($files as $key => $value) {
  6.         $path = $dir . DIRECTORY_SEPARATOR . $value;
  7.         if (!is_dir($path)) {
  8.             $results[] = $path;
  9.         } else if ($value != "." && $value != "..") {
  10.             getDirContents($path, $results);
  11.             $results[] = $path;
  12.         }
  13.     }
  14.  
  15.     return $results;
  16. }
  17.  
  18. $filetree = array();
  19.  
  20. foreach(getDirContents('./js') as $path)
  21. {
  22.     $split = explode(DIRECTORY_SEPARATOR, $path);
  23.     $last = $split[count($split) - 1];
  24.     $fileOrDir = explode('.', $last);
  25.  
  26.     $var_ref =& $filetree;
  27.     foreach ($split as $path_item)
  28.     {
  29.         $var_ref =& $var_ref[$path_item];
  30.     }
  31. }
  32.  
  33. echo '<pre>';
  34. print_r($filetree);
  35. echo '</pre>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement