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

Revision 8627, 4.0 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            echo (lfReadFile($_POST['select_file']));
56           
57            exit;           
58        }
59    }
60    break;
61   
62case 'delete':
63    break;
64   
65default :
66    // ½é´üɽ¼¨¤Ï¥ë¡¼¥È¥Ç¥£¥ì¥¯¥È¥ê(user_data/upload/)¤òɽ¼¨
67    $now_dir = $top_dir;
68    break;
69}
70// ¸½ºß¤Î¥Ç¥£¥ì¥¯¥È¥êÇÛ²¼¤Î¥Õ¥¡¥¤¥ë°ìÍ÷¤ò¼èÆÀ
71$objPage->arrFileList = lfGetFileList($now_dir);
72$objPage->tpl_now_file = $now_dir;
73
74sfprintr($now_dir);
75
76$objView->assignobj($objPage);
77$objView->display("tree.tpl");
78
79//-----------------------------------------------------------------------------------------------------------------------------------
80
81/*
82 * ´Ø¿ô̾¡§lfGetFileList()
83 * ÀâÌÀ¡¡¡§»ØÄê¥Ñ¥¹ÇÛ²¼¤Î¥Ç¥£¥ì¥¯¥È¥ê¼èÆÀ
84 * °ú¿ô1 ¡§¥Ä¥ê¡¼¤ò³ÊǼÇÛÎó
85 * °ú¿ô2 ¡§¼èÆÀ¤¹¤ë¥Ç¥£¥ì¥¯¥È¥ê¥Ñ¥¹
86 */
87function lfGetFileList($dir) {
88    $arrFileList = array();
89    if (is_dir($dir)) {
90        if ($dh = opendir($dir)) {
91            $cnt = 0;
92            while (($file = readdir($dh)) !== false) {
93                // ./ ¤È ../¤ò½ü¤¯¥Õ¥¡¥¤¥ë¤Î¤ß¤ò¼èÆÀ
94                if($file != "." && $file != "..") {
95                    // ¹ÔËö¤Î/¤ò¼è¤ê½ü¤¯
96                    $dir = ereg_replace("\/$", "", $dir);
97                    $path = $dir."/".$file;
98                    $arrFileList[$cnt]['file_name'] = $file;
99                    $arrFileList[$cnt]['file_path'] = $path;
100                    $arrFileList[$cnt]['file_size'] = getDirSize($path);
101                    $arrFileList[$cnt]['file_time'] = date("Y/m/d", filemtime($path));
102                    $cnt++;
103                }
104            }
105            closedir($dh);
106        }
107    }
108   
109    return $arrFileList;
110}
111
112/*
113 * ´Ø¿ô̾¡§getDirSize()
114 * ÀâÌÀ¡¡¡§»ØÄꤷ¤¿¥Ç¥£¥ì¥¯¥È¥ê¤Î¥Ð¥¤¥È¿ô¤ò¼èÆÀ
115 * °ú¿ô1 ¡§¥Õ¥¡¥¤¥ë³ÊǼÇÛÎó
116 */
117function getDirSize($dir) {
118    if(file_exists($dir)) {
119        // ¥Ç¥£¥ì¥¯¥È¥ê¤Î¾ì¹ç²¼ÁØ¥Õ¥¡¥¤¥ë¤ÎÁíÎ̤ò¼èÆÀ
120        if (is_dir($dir)) {
121            $handle = opendir($dir);
122            while ($file = readdir($handle)) {
123                $path = $dir."/".$file;
124                if ($file != '..' && $file != '.' && !is_dir($path)) {
125                    $bytes += filesize($path);
126                } else if (is_dir($path) && $file != '..' && $file != '.') {
127                    $bytes += getDirSize($path);
128                }
129            }
130        } else {
131            // ¥Õ¥¡¥¤¥ë¤Î¾ì¹ç
132            $bytes = filesize($dir);
133        }
134    } else {
135        // ¥Ç¥£¥ì¥¯¥È¥ê¤¬Â¸ºß¤·¤Ê¤¤¾ì¹ç¤Ï0byte¤òÊÖ¤¹
136        $bytes = 0;
137    }
138   
139    if($bytes == "") $bytes = 0;
140   
141    return $bytes;
142}
143
144/*
145 * ´Ø¿ô̾¡§lfErrorCheck()
146 * ÀâÌÀ¡¡¡§¥¨¥é¡¼¥Á¥§¥Ã¥¯
147 */
148function lfErrorCheck() {
149
150    if($_POST['select_file'] == '') {
151        $arrErr['select_file'] = "¢¨¡¡¥Õ¥¡¥¤¥ë¤¬ÁªÂò¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£";
152    }
153    return $arrErr;
154}
155
156/*
157 * ´Ø¿ô̾¡§lfReadFile()
158 * °ú¿ô1 ¡§¥Õ¥¡¥¤¥ë¥Ñ¥¹
159 * ÀâÌÀ¡¡¡§¥Õ¥¡¥¤¥ëÆÉ¹þ
160 */
161function lfReadFile($filename) {
162    $str = "";
163    // ¥Ð¥¤¥Ê¥ê¥â¡¼¥É¤Ç¥ª¡¼¥×¥ó
164    $fp = @fopen($filename, "rb" );
165    //¥Õ¥¡¥¤¥ëÆâÍÆ¤òÁ´¤ÆÊÑ¿ô¤ËÆÉ¤ß¹þ¤à
166    if($fp) {
167        $str = @fread($fp, filesize($filename)+1);
168    }
169    @fclose($fp);
170    // ²þ¹Ô¥³¡¼¥É¤ÎÁ°¤Ë<br />¤òÁÞÆþ
171    $str = nl2br($str);
172    return $str;
173}
174?>
Note: See TracBrowser for help on using the repository browser.