Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function require_all($dir){
- // 最後に / が付加されていない場合は、付加
- $dir_last = substr($dir, -1);
- if($dir_last !== "/"){
- $dir .= "/";
- }
- // 指定されたパスが有効なディレクトリ名であればロード
- if (is_dir($dir)) {
- // 有効なディレクトリ名
- // → ディレクトリのオープンとハンドルの取得を試みる
- if ($dh = opendir($dir)) {
- // ディレクトリハンドル取得成功
- // → ファイル一覧を取得しながら反復処理
- while (($file = readdir($dh)) !== false) {
- if($file !== "." && $file !== "..") {
- $filename = $dir . $file;
- if (is_dir($filename))
- // サブディレクトリ内も処理
- // → 再帰処理
- require_all($filename);
- else {
- // ファイル
- if (substr($filename, strrpos($filename, '.') + 1) === "php")
- // PHPファイル
- // → require_once
- require_once($filename);
- }
- }
- }
- closedir($dh);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement