source: temp/trunk/html/test/uehara/tree.php @ 8618

Revision 8618, 3.6 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 * Copyright(c) 2000-2006 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7require_once("../../require.php");
8
9class LC_Page{
10    function LC_Page() {
11    }
12}
13
14$top_dir = USER_PATH;
15
16$objPage = new LC_Page();
17$objView = new SC_UserView("./templates");
18$objQuery = new SC_Query();
19
20// ¸½ºß¤Î³¬Áؤò¼èÆÀ
21if($_POST['mode'] != "") {
22    $now_dir = $_POST['now_file'];
23}
24
25switch($_POST['mode']) {
26
27case 'view':
28    // ¥¨¥é¡¼¥Á¥§¥Ã¥¯
29    if(!is_array(lfErrorCheck())) {
30   
31        // ÁªÂò¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤¬¥Ç¥£¥ì¥¯¥È¥ê¤Ê¤é°Üư
32        if(is_dir($_POST['select_file'])) {
33            $now_dir = $_POST['select_file'];
34        } else {
35            // javascript¤ÇÊÌÁëɽ¼¨(¥Æ¥ó¥×¥ì¡¼¥È¦¤ËÅϤ¹)
36            $file_url = ereg_replace(USER_PATH, "", $_POST['select_file']);
37            $objPage->tpl_javascript = "win02('./file_view.php?file=". $file_url ."', 'user_data', '600', '400');";
38        }
39    }
40    break;
41
42case 'download':
43
44    // ¥¨¥é¡¼¥Á¥§¥Ã¥¯
45    if(!is_array(lfErrorCheck())) {
46        if(is_dir($_POST['select_file'])) {
47            // ¥Ç¥£¥ì¥¯¥È¥ê¤Î¾ì¹ç¤Ïjavascript¥¨¥é¡¼
48            $objPage->tpl_javascript = "alert('¢¨¡¡¥Ç¥£¥ì¥¯¥È¥ê¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤³¤È¤Ï½ÐÍè¤Þ¤»¤ó¡£');";
49        } else {
50            // ¥Õ¥¡¥¤¥ë¤Î¾ì¹ç¤Ï¥À¥¦¥ó¥í¡¼¥É¤µ¤»¤ë
51            Header("Content-disposition: attachment; filename=".basename($_POST['select_file']));
52            Header("Content-type: application/octet-stream; name=".basename($_POST['select_file']));
53            Header("Cache-Control: ");
54            Header("Pragma: ");
55        }
56    }
57    break;
58   
59case 'delete':
60    break;
61   
62default :
63    // ½é´üɽ¼¨¤Ï¥ë¡¼¥È¥Ç¥£¥ì¥¯¥È¥ê(user_data/upload/)¤òɽ¼¨
64    $now_dir = $top_dir;
65    break;
66}
67// ¸½ºß¤Î¥Ç¥£¥ì¥¯¥È¥êÇÛ²¼¤Î¥Õ¥¡¥¤¥ë°ìÍ÷¤ò¼èÆÀ
68$objPage->arrFileList = lfGetFileList($now_dir);
69$objPage->tpl_now_file = $now_dir;
70
71sfprintr($now_dir);
72
73$objView->assignobj($objPage);
74$objView->display("tree.tpl");
75
76//-----------------------------------------------------------------------------------------------------------------------------------
77
78/*
79 * ´Ø¿ô̾¡§lfGetFileList()
80 * ÀâÌÀ¡¡¡§»ØÄê¥Ñ¥¹ÇÛ²¼¤Î¥Ç¥£¥ì¥¯¥È¥ê¼èÆÀ
81 * °ú¿ô1 ¡§¥Ä¥ê¡¼¤ò³ÊǼÇÛÎó
82 * °ú¿ô2 ¡§¼èÆÀ¤¹¤ë¥Ç¥£¥ì¥¯¥È¥ê¥Ñ¥¹
83 */
84function lfGetFileList($dir) {
85    $arrFileList = array();
86    if (is_dir($dir)) {
87        if ($dh = opendir($dir)) {
88            $cnt = 0;
89            while (($file = readdir($dh)) !== false) {
90                // ./ ¤È ../¤ò½ü¤¯¥Õ¥¡¥¤¥ë¤Î¤ß¤ò¼èÆÀ
91                if($file != "." && $file != "..") {
92                    // ¹ÔËö¤Î/¤ò¼è¤ê½ü¤¯
93                    $dir = ereg_replace("\/$", "", $dir);
94                    $path = $dir."/".$file;
95                    $arrFileList[$cnt]['file_name'] = $file;
96                    $arrFileList[$cnt]['file_path'] = $path;
97                    $arrFileList[$cnt]['file_size'] = getDirSize($path);
98                    $arrFileList[$cnt]['file_time'] = date("Y/m/d", filemtime($path));
99                    $cnt++;
100                }
101            }
102            closedir($dh);
103        }
104    }
105   
106    return $arrFileList;
107}
108
109/*
110 * ´Ø¿ô̾¡§getDirSize()
111 * ÀâÌÀ¡¡¡§»ØÄꤷ¤¿¥Ç¥£¥ì¥¯¥È¥ê¤Î¥Ð¥¤¥È¿ô¤ò¼èÆÀ
112 * °ú¿ô1 ¡§¥Õ¥¡¥¤¥ë³ÊǼÇÛÎó
113 */
114function getDirSize($dir) {
115    if(file_exists($dir)) {
116        // ¥Ç¥£¥ì¥¯¥È¥ê¤Î¾ì¹ç²¼ÁØ¥Õ¥¡¥¤¥ë¤ÎÁíÎ̤ò¼èÆÀ
117        if (is_dir($dir)) {
118            $handle = opendir($dir);
119            while ($file = readdir($handle)) {
120                $path = $dir."/".$file;
121                if ($file != '..' && $file != '.' && !is_dir($path)) {
122                    $bytes += filesize($path);
123                } else if (is_dir($path) && $file != '..' && $file != '.') {
124                    $bytes += getDirSize($path);
125                }
126            }
127        } else {
128            // ¥Õ¥¡¥¤¥ë¤Î¾ì¹ç
129            $bytes = filesize($dir);
130        }
131    } else {
132        // ¥Ç¥£¥ì¥¯¥È¥ê¤¬Â¸ºß¤·¤Ê¤¤¾ì¹ç¤Ï0byte¤òÊÖ¤¹
133        $bytes = 0;
134    }
135   
136    if($bytes == "") $bytes = 0;
137   
138    return $bytes;
139}
140
141/*
142 * ´Ø¿ô̾¡§lfErrorCheck()
143 * ÀâÌÀ¡¡¡§¥¨¥é¡¼¥Á¥§¥Ã¥¯
144 */
145function lfErrorCheck() {
146
147    if($_POST['select_file'] == '') {
148        $arrErr['select_file'] = "¢¨¡¡¥Õ¥¡¥¤¥ë¤¬ÁªÂò¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£";
149    }
150    return $arrErr;
151}
152?>
Note: See TracBrowser for help on using the repository browser.