| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | $default_dir = "/home/web/test.ec-cube.net/html/user_data/"; |
|---|
| 5 | print_r(sfGetFileTree($default_dir)); |
|---|
| 6 | |
|---|
| 7 | /* |
|---|
| 8 | * ´Ø¿ô̾¡§sfGetFileTree() |
|---|
| 9 | * ÀâÌÀ¡¡¡§¥Ä¥ê¡¼À¸À®ÍÑÇÛÎó¼èÆÀ(javascript¤ËÅϤ¹ÍÑ) |
|---|
| 10 | * °ú¿ô1 ¡§¥Ç¥£¥ì¥¯¥È¥ê |
|---|
| 11 | */ |
|---|
| 12 | function sfGetFileTree($dir) { |
|---|
| 13 | |
|---|
| 14 | $cnt = 0; |
|---|
| 15 | $arrTree = array(); |
|---|
| 16 | $default_rank = count(split('/', $dir)); |
|---|
| 17 | |
|---|
| 18 | // ºÇ¾å°ÌÁØ |
|---|
| 19 | if(sfDirChildExists($dir)) { |
|---|
| 20 | $file_type = "_parent"; |
|---|
| 21 | } else { |
|---|
| 22 | $file_type = "_child"; |
|---|
| 23 | } |
|---|
| 24 | $arrTree[$cnt] = array($cnt, $file_type, $dir, 0); |
|---|
| 25 | $cnt++; |
|---|
| 26 | sfprintr($arrTree[$cnt]); |
|---|
| 27 | sfGetFileTreeSub($dir, $default_rank, $cnt, $arrTree); |
|---|
| 28 | |
|---|
| 29 | return $arrTree; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | function sfGetFileTreeSub($dir, $default_rank, &$cnt, &$arrTree) { |
|---|
| 33 | |
|---|
| 34 | if(file_exists($dir)) { |
|---|
| 35 | if ($handle = opendir("$dir")) { |
|---|
| 36 | while (false !== ($item = readdir($handle))) { |
|---|
| 37 | if ($item != "." && $item != "..") { |
|---|
| 38 | // ʸËö¤Î/¤ò¼è¤ê½ü¤¯ |
|---|
| 39 | $dir = ereg_replace("/$", "", $dir); |
|---|
| 40 | $path = $dir."/".$item; |
|---|
| 41 | // ¥Ç¥£¥ì¥¯¥È¥ê¤Î¤ß¼èÆÀ |
|---|
| 42 | if (is_dir($path)) { |
|---|
| 43 | $path; |
|---|
| 44 | if(sfDirChildExists($path)) { |
|---|
| 45 | $file_type = "_parent"; |
|---|
| 46 | } else { |
|---|
| 47 | $file_type = "_child"; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | // ³¬Áؤò³ä¤ê½Ð¤¹ |
|---|
| 51 | $arrCnt = split('/', $path); |
|---|
| 52 | $rank = count($arrCnt); |
|---|
| 53 | $rank = $rank - $default_rank + 1; |
|---|
| 54 | |
|---|
| 55 | // javascript¤Î¥Ä¥ê¡¼À¸À®ÍѤÎÇÛÎó¤òºîÀ® |
|---|
| 56 | $arrTree[$cnt] = array($cnt, $file_type, $path, $rank); |
|---|
| 57 | $cnt++; |
|---|
| 58 | // ²¼Áإǥ£¥ì¥¯¥È¥ê¼èÆÀ¤Î°Ù¡¢ºÆµ¢Åª¤Ë¸Æ¤Ó½Ð¤¹ |
|---|
| 59 | sfGetFileTreeSub($path, $default_rank, $cnt, $arrTree); |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | closedir($handle); |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | /* |
|---|
| 69 | * ´Ø¿ô̾¡§sfDirChildExists() |
|---|
| 70 | * ÀâÌÀ¡¡¡§»ØÄꤷ¤¿¥Ç¥£¥ì¥¯¥È¥êÇÛ²¼¤Ë¥Õ¥¡¥¤¥ë¤¬¤¢¤ë¤« |
|---|
| 71 | * °ú¿ô1 ¡§¥Ç¥£¥ì¥¯¥È¥ê |
|---|
| 72 | */ |
|---|
| 73 | function sfDirChildExists($dir) { |
|---|
| 74 | if(file_exists($dir)) { |
|---|
| 75 | // ¥Ç¥£¥ì¥¯¥È¥ê¤Î¾ì¹ç²¼ÁØ¥Õ¥¡¥¤¥ë¤ÎÁíÎ̤ò¼èÆÀ |
|---|
| 76 | if (is_dir($dir)) { |
|---|
| 77 | $handle = opendir($dir); |
|---|
| 78 | while ($file = readdir($handle)) { |
|---|
| 79 | // ¹ÔËö¤Î/¤ò¼è¤ê½ü¤¯ |
|---|
| 80 | $dir = ereg_replace("/$", "", $dir); |
|---|
| 81 | $path = $dir."/".$file; |
|---|
| 82 | if ($file != '..' && $file != '.') { |
|---|
| 83 | return true; |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | return false; |
|---|
| 90 | } |
|---|
| 91 | ?> |
|---|