Require all files in a folder

后端 未结 9 1443
南旧
南旧 2020-12-28 13:13

Is there an easy way to programmatically require all files in a folder?

9条回答
  •  余生分开走
    2020-12-28 13:36

    Solution using opendir, readdir, closedir. This also includes subdirectories.

    4 && substr($fullfile,-4) == '.php') {
                    require $fullfile;
                }
            }
        }
    
        closedir($dirhandle);
    }        
    
    //Call like
    _require_all(__DIR__ . '/../vendor/vlucas/phpdotenv/src');
    

提交回复
热议问题