scandir to only show folders, not files

后端 未结 4 2021
一整个雨季
一整个雨季 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:25

    You could just use your array_map function combined with glob

    $folders = array_map(function($dir) {
        return basename($dir);
    }, glob('../images/*', GLOB_ONLYDIR));
    

    Yes, I copied a part of it of dev-null-dweller, but I find my solution a bit more re-useable.

提交回复
热议问题