Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. function require_all($dir){
  2. // 最後に / が付加されていない場合は、付加
  3. $dir_last = substr($dir, -1);
  4. if($dir_last !== "/"){
  5. $dir .= "/";
  6. }
  7.  
  8. // 指定されたパスが有効なディレクトリ名であればロード
  9. if (is_dir($dir)) {
  10. // 有効なディレクトリ名
  11. // → ディレクトリのオープンとハンドルの取得を試みる
  12. if ($dh = opendir($dir)) {
  13. // ディレクトリハンドル取得成功
  14. // → ファイル一覧を取得しながら反復処理
  15. while (($file = readdir($dh)) !== false) {
  16. if($file !== "." && $file !== "..") {
  17. $filename = $dir . $file;
  18. if (is_dir($filename))
  19. // サブディレクトリ内も処理
  20. // → 再帰処理
  21. require_all($filename);
  22. else {
  23. // ファイル
  24. if (substr($filename, strrpos($filename, '.') + 1) === "php")
  25. // PHPファイル
  26. // → require_once
  27. require_once($filename);
  28. }
  29. }
  30. }
  31. closedir($dh);
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement