source: temp/trunk/html/test/uehara/test.php @ 8779

Revision 8779, 1.8 KB checked in by uehara, 20 years ago (diff)

blank

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