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

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