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

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