[PHP] Removing Directories from Listing

    • [PHP] Removing Directories from Listing

      Righto, here is my current code to print out the files (under $filedir):

      PHP Source Code

      1. $dispdir = false;
      2. function directoryToArray($directory, $recursive) {
      3. $me = basename($_SERVER['PHP_SELF']);
      4. $array_items = array();
      5. if ($handle = opendir($directory)) {
      6. while(false !== ($file = readdir($handle))) {
      7. if ($file != '.' && $file != '..' && $file != $me && substr($file,0,1) != '.') {
      8. if (is_dir($directory.'/'.$file)) {
      9. if($recursive) {
      10. $array_items = array_merge($array_items, directoryToArray($directory.'/'. $file, $recursive));
      11. }
      12. if($dispdir == true) {
      13. $file = $directory.'/'.$file;
      14. $array_items[] = preg_replace('/\/\//si', '/', $file);
      15. }
      16. } else {
      17. $file = $directory .'/'. $file;
      18. $array_items[] = preg_replace('/\/\//si', '/', $file);
      19. }
      20. }
      21. }
      22. closedir($handle);
      23. asort($array_items);
      24. }
      25. return $array_items;
      26. }
      27. $filelist = directoryToArray($filedir, $recursivelist);
      28. foreach($filelist as $file) {
      29. $ext = substr(strrchr($file, '.'), 1);
      30. if(in_array($ext,$valid_ext) && is_writable($file)) {
      31. echo '<option value="'.$file.'">$file</option>';
      32. }
      33. }
      Display All
      The lines:

      PHP Source Code

      1. $file = $directory .'/'. $file;
      2. $array_items[] = preg_replace('/\/\//si', '/', $file);
      SHOULD remove the directories from the listing, but they don't. Without them, no files are displayed. What's going on?

      Hopefully some of you are in to PHP. :)