scandir to only show folders, not files

后端 未结 4 2017
一整个雨季
一整个雨季 2021-01-01 22:49

I have a bit of PHP used to pulled a list of files from my image directory - it\'s used in a form to select where an uploaded image will be saved. Below is the code:

4条回答
  •  难免孤独
    2021-01-01 23:35

    The is_dir() function requires an absolute path to the item that it is checking.

    $base_dir    = get_home_path() . '/downloads'; 
    //get_home_path() is a wordpress function
    $sub_dirs = array();
    $dir_to_check = scandir($dir);
    foreach ($dir_to_check as $item){
      if ($item != '..' && $item != '.' && is_dir($base_dir . "/" . $item)){
        array_push($sub_dirs, $item);
      }
    }
    

提交回复
热议问题