| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * http://www.lockon.co.jp/
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | /*
|
|---|
| 9 | * ´Ø¿ô̾¡§sfGetFileList()
|
|---|
| 10 | * ÀâÌÀ¡¡¡§»ØÄê¥Ñ¥¹ÇÛ²¼¤Î¥Ç¥£¥ì¥¯¥È¥ê¼èÆÀ
|
|---|
| 11 | * °ú¿ô1 ¡§¼èÆÀ¤¹¤ë¥Ç¥£¥ì¥¯¥È¥ê¥Ñ¥¹
|
|---|
| 12 | */
|
|---|
| 13 | function sfGetFileList($dir) {
|
|---|
| 14 | $arrFileList = array();
|
|---|
| 15 | $arrDirList = array();
|
|---|
| 16 |
|
|---|
| 17 | if (is_dir($dir)) {
|
|---|
| 18 | if ($dh = opendir($dir)) {
|
|---|
| 19 | $cnt = 0;
|
|---|
| 20 | // ¹ÔËö¤Î/¤ò¼è¤ê½ü¤¯
|
|---|
| 21 | while (($file = readdir($dh)) !== false) $arrDir[] = $file;
|
|---|
| 22 | $dir = ereg_replace("/$", "", $dir);
|
|---|
| 23 | // ¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¤È¿ô»ú¤Ç¥½¡¼¥È
|
|---|
| 24 | natcasesort($arrDir);
|
|---|
| 25 | foreach($arrDir as $file) {
|
|---|
| 26 | // ./ ¤È ../¤ò½ü¤¯¥Õ¥¡¥¤¥ë¤Î¤ß¤ò¼èÆÀ
|
|---|
| 27 | if($file != "." && $file != "..") {
|
|---|
| 28 |
|
|---|
| 29 | $path = $dir."/".$file;
|
|---|
| 30 | // SELECTÆâ¤Î¸«¤¿ÌܤòÀ°¤¨¤ë¤¿¤á»ØÄêʸ»ú¿ô¤ÇÀÚ¤ë
|
|---|
| 31 | $file_name = sfCutString($file, FILE_NAME_LEN);
|
|---|
| 32 | $file_size = sfCutString(sfGetDirSize($path), FILE_NAME_LEN);
|
|---|
| 33 | $file_time = date("Y/m/d", filemtime($path));
|
|---|
| 34 |
|
|---|
| 35 | // ¥Ç¥£¥ì¥¯¥È¥ê¤È¥Õ¥¡¥¤¥ë¤Ç³ÊǼÇÛÎó¤òÊѤ¨¤ë
|
|---|
| 36 | if(is_dir($path)) {
|
|---|
| 37 | $arrDirList[$cnt]['file_name'] = $file;
|
|---|
| 38 | $arrDirList[$cnt]['file_path'] = $path;
|
|---|
| 39 | $arrDirList[$cnt]['file_size'] = $file_size;
|
|---|
| 40 | $arrDirList[$cnt]['file_time'] = $file_time;
|
|---|
| 41 | $arrDirList[$cnt]['is_dir'] = true;
|
|---|
| 42 | } else {
|
|---|
| 43 | $arrFileList[$cnt]['file_name'] = $file;
|
|---|
| 44 | $arrFileList[$cnt]['file_path'] = $path;
|
|---|
| 45 | $arrFileList[$cnt]['file_size'] = $file_size;
|
|---|
| 46 | $arrFileList[$cnt]['file_time'] = $file_time;
|
|---|
| 47 | $arrFileList[$cnt]['is_dir'] = false;
|
|---|
| 48 | }
|
|---|
| 49 | $cnt++;
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 | closedir($dh);
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | // ¥Õ¥©¥ë¥À¤òÀèÆ¬¤Ë¤·¤Æ¥Þ¡¼¥¸
|
|---|
| 57 | return array_merge($arrDirList, $arrFileList);
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | /*
|
|---|
| 61 | * ´Ø¿ô̾¡§sfGetDirSize()
|
|---|
| 62 | * ÀâÌÀ¡¡¡§»ØÄꤷ¤¿¥Ç¥£¥ì¥¯¥È¥ê¤Î¥Ð¥¤¥È¿ô¤ò¼èÆÀ
|
|---|
| 63 | * °ú¿ô1 ¡§¥Ç¥£¥ì¥¯¥È¥ê
|
|---|
| 64 | */
|
|---|
| 65 | function sfGetDirSize($dir) {
|
|---|
| 66 | if(file_exists($dir)) {
|
|---|
| 67 | // ¥Ç¥£¥ì¥¯¥È¥ê¤Î¾ì¹ç²¼ÁØ¥Õ¥¡¥¤¥ë¤ÎÁíÎ̤ò¼èÆÀ
|
|---|
| 68 | if (is_dir($dir)) {
|
|---|
| 69 | $handle = opendir($dir);
|
|---|
| 70 | while ($file = readdir($handle)) {
|
|---|
| 71 | // ¹ÔËö¤Î/¤ò¼è¤ê½ü¤¯
|
|---|
| 72 | $dir = ereg_replace("/$", "", $dir);
|
|---|
| 73 | $path = $dir."/".$file;
|
|---|
| 74 | if ($file != '..' && $file != '.' && !is_dir($path)) {
|
|---|
| 75 | $bytes += filesize($path);
|
|---|
| 76 | } else if (is_dir($path) && $file != '..' && $file != '.') {
|
|---|
| 77 | // ²¼ÁØ¥Õ¥¡¥¤¥ë¤Î¥Ð¥¤¥È¿ô¤ò¼èÆÀ¤¹¤ë°Ù¡¢ºÆµ¢Åª¤Ë¸Æ¤Ó½Ð¤¹¡£
|
|---|
| 78 | $bytes += sfGetDirSize($path);
|
|---|
| 79 | }
|
|---|
| 80 | }
|
|---|
| 81 | } else {
|
|---|
| 82 | // ¥Õ¥¡¥¤¥ë¤Î¾ì¹ç
|
|---|
| 83 | $bytes = filesize($dir);
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 | // ¥Ç¥£¥ì¥¯¥È¥ê(¥Õ¥¡¥¤¥ë)¤¬Â¸ºß¤·¤Ê¤¤¾ì¹ç¤Ï0byte¤òÊÖ¤¹
|
|---|
| 87 | if($bytes == "") $bytes = 0;
|
|---|
| 88 |
|
|---|
| 89 | return $bytes;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | /*
|
|---|
| 93 | * ´Ø¿ô̾¡§sfDeleteDir()
|
|---|
| 94 | * ÀâÌÀ¡¡¡§»ØÄꤷ¤¿¥Ç¥£¥ì¥¯¥È¥ê¤òºï½ü
|
|---|
| 95 | * °ú¿ô1 ¡§ºï½ü¥Õ¥¡¥¤¥ë
|
|---|
| 96 | */
|
|---|
| 97 | function sfDeleteDir($dir) {
|
|---|
| 98 | $arrResult = array();
|
|---|
| 99 | if(file_exists($dir)) {
|
|---|
| 100 | // ¥Ç¥£¥ì¥¯¥È¥ê¤«¥Á¥§¥Ã¥¯
|
|---|
| 101 | if (is_dir($dir)) {
|
|---|
| 102 | if ($handle = opendir("$dir")) {
|
|---|
| 103 | $cnt = 0;
|
|---|
| 104 | while (false !== ($item = readdir($handle))) {
|
|---|
| 105 | if ($item != "." && $item != "..") {
|
|---|
| 106 | if (is_dir("$dir/$item")) {
|
|---|
| 107 | sfDeleteDir("$dir/$item");
|
|---|
| 108 | } else {
|
|---|
| 109 | $arrResult[$cnt]['result'] = @unlink("$dir/$item");
|
|---|
| 110 | $arrResult[$cnt]['file_name'] = "$dir/$item";
|
|---|
| 111 | }
|
|---|
| 112 | }
|
|---|
| 113 | $cnt++;
|
|---|
| 114 | }
|
|---|
| 115 | }
|
|---|
| 116 | closedir($handle);
|
|---|
| 117 | $arrResult[$cnt]['result'] = @rmdir($dir);
|
|---|
| 118 | $arrResult[$cnt]['file_name'] = "$dir/$item";
|
|---|
| 119 | } else {
|
|---|
| 120 | // ¥Õ¥¡¥¤¥ëºï½ü
|
|---|
| 121 | $arrResult[0]['result'] = @unlink("$dir");
|
|---|
| 122 | $arrResult[0]['file_name'] = "$dir";
|
|---|
| 123 | }
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | return $arrResult;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | /*
|
|---|
| 130 | * ´Ø¿ô̾¡§sfGetFileTree()
|
|---|
| 131 | * ÀâÌÀ¡¡¡§¥Ä¥ê¡¼À¸À®ÍÑÇÛÎó¼èÆÀ(javascript¤ËÅϤ¹ÍÑ)
|
|---|
| 132 | * °ú¿ô1 ¡§¥Ç¥£¥ì¥¯¥È¥ê
|
|---|
| 133 | * °ú¿ô2 ¡§¸½ºß¤Î¥Ä¥ê¡¼¤Î¾õÂÖ³«¤¤¤Æ¤¤¤ë¥Õ¥©¥ë¥À¤Î¥Ñ¥¹¤¬ | ¶èÀÚ¤ê¤Ç³ÊǼ
|
|---|
| 134 | */
|
|---|
| 135 | function sfGetFileTree($dir, $tree_status) {
|
|---|
| 136 |
|
|---|
| 137 | $cnt = 0;
|
|---|
| 138 | $arrTree = array();
|
|---|
| 139 | $default_rank = count(split('/', $dir));
|
|---|
| 140 |
|
|---|
| 141 | // ʸËö¤Î/¤ò¼è¤ê½ü¤¯
|
|---|
| 142 | $dir = ereg_replace("/$", "", $dir);
|
|---|
| 143 | // ºÇ¾å°ÌÁؤò³ÊǼ(user_data/)
|
|---|
| 144 | if(sfDirChildExists($dir)) {
|
|---|
| 145 | $arrTree[$cnt]['type'] = "_parent";
|
|---|
| 146 | } else {
|
|---|
| 147 | $arrTree[$cnt]['type'] = "_child";
|
|---|
| 148 | }
|
|---|
| 149 | $arrTree[$cnt]['path'] = $dir;
|
|---|
| 150 | $arrTree[$cnt]['rank'] = 0;
|
|---|
| 151 | $arrTree[$cnt]['count'] = $cnt;
|
|---|
| 152 | // ½é´üɽ¼¨¤Ï¥ª¡¼¥×¥ó
|
|---|
| 153 | if($_POST['mode'] != '') {
|
|---|
| 154 | $arrTree[$cnt]['open'] = lfIsFileOpen($dir, $tree_status);
|
|---|
| 155 | } else {
|
|---|
| 156 | $arrTree[$cnt]['open'] = true;
|
|---|
| 157 | }
|
|---|
| 158 | $cnt++;
|
|---|
| 159 |
|
|---|
| 160 | sfGetFileTreeSub($dir, $default_rank, $cnt, $arrTree, $tree_status);
|
|---|
| 161 |
|
|---|
| 162 | return $arrTree;
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | /*
|
|---|
| 166 | * ´Ø¿ô̾¡§sfGetFileTree()
|
|---|
| 167 | * ÀâÌÀ¡¡¡§¥Ä¥ê¡¼À¸À®ÍÑÇÛÎó¼èÆÀ(javascript¤ËÅϤ¹ÍÑ)
|
|---|
| 168 | * °ú¿ô1 ¡§¥Ç¥£¥ì¥¯¥È¥ê
|
|---|
| 169 | * °ú¿ô2 ¡§¥Ç¥Õ¥©¥ë¥È¤Î³¬ÁØ(/¶èÀÚ¤ê¤Ç¡¡0,1,2¡¦¡¦¡¦¤È¥«¥¦¥ó¥È)
|
|---|
| 170 | * °ú¿ô3 ¡§Ï¢ÈÖ
|
|---|
| 171 | * °ú¿ô4 ¡§¸½ºß¤Î¥Ä¥ê¡¼¤Î¾õÂÖ³«¤¤¤Æ¤¤¤ë¥Õ¥©¥ë¥À¤Î¥Ñ¥¹¤¬ | ¶èÀÚ¤ê¤Ç³ÊǼ
|
|---|
| 172 | */
|
|---|
| 173 | function sfGetFileTreeSub($dir, $default_rank, &$cnt, &$arrTree, $tree_status) {
|
|---|
| 174 |
|
|---|
| 175 | if(file_exists($dir)) {
|
|---|
| 176 | if ($handle = opendir("$dir")) {
|
|---|
| 177 | while (false !== ($item = readdir($handle))) $arrDir[] = $item;
|
|---|
| 178 | // ¥¢¥ë¥Õ¥¡¥Ù¥Ã¥È¤È¿ô»ú¤Ç¥½¡¼¥È
|
|---|
| 179 | natcasesort($arrDir);
|
|---|
| 180 | foreach($arrDir as $item) {
|
|---|
| 181 | if ($item != "." && $item != "..") {
|
|---|
| 182 | // ʸËö¤Î/¤ò¼è¤ê½ü¤¯
|
|---|
| 183 | $dir = ereg_replace("/$", "", $dir);
|
|---|
| 184 | $path = $dir."/".$item;
|
|---|
| 185 | // ¥Ç¥£¥ì¥¯¥È¥ê¤Î¤ß¼èÆÀ
|
|---|
| 186 | if (is_dir($path)) {
|
|---|
| 187 | $arrTree[$cnt]['path'] = $path;
|
|---|
| 188 | if(sfDirChildExists($path)) {
|
|---|
| 189 | $arrTree[$cnt]['type'] = "_parent";
|
|---|
| 190 | } else {
|
|---|
| 191 | $arrTree[$cnt]['type'] = "_child";
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | // ³¬Áؤò³ä¤ê½Ð¤¹
|
|---|
| 195 | $arrCnt = split('/', $path);
|
|---|
| 196 | $rank = count($arrCnt);
|
|---|
| 197 | $arrTree[$cnt]['rank'] = $rank - $default_rank + 1;
|
|---|
| 198 | $arrTree[$cnt]['count'] = $cnt;
|
|---|
| 199 | // ¥Õ¥©¥ë¥À¤¬³«¤¤¤Æ¤¤¤ë¤«
|
|---|
| 200 | $arrTree[$cnt]['open'] = lfIsFileOpen($path, $tree_status);
|
|---|
| 201 | $cnt++;
|
|---|
| 202 | // ²¼Áإǥ£¥ì¥¯¥È¥ê¼èÆÀ¤Î°Ù¡¢ºÆµ¢Åª¤Ë¸Æ¤Ó½Ð¤¹
|
|---|
| 203 | sfGetFileTreeSub($path, $default_rank, $cnt, $arrTree, $tree_status);
|
|---|
| 204 | }
|
|---|
| 205 | }
|
|---|
| 206 | }
|
|---|
| 207 | }
|
|---|
| 208 | closedir($handle);
|
|---|
| 209 | }
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | /*
|
|---|
| 213 | * ´Ø¿ô̾¡§sfDirChildExists()
|
|---|
| 214 | * ÀâÌÀ¡¡¡§»ØÄꤷ¤¿¥Ç¥£¥ì¥¯¥È¥êÇÛ²¼¤Ë¥Õ¥¡¥¤¥ë¤¬¤¢¤ë¤«
|
|---|
| 215 | * °ú¿ô1 ¡§¥Ç¥£¥ì¥¯¥È¥ê
|
|---|
| 216 | */
|
|---|
| 217 | function sfDirChildExists($dir) {
|
|---|
| 218 | if(file_exists($dir)) {
|
|---|
| 219 | if (is_dir($dir)) {
|
|---|
| 220 | $handle = opendir($dir);
|
|---|
| 221 | while ($file = readdir($handle)) {
|
|---|
| 222 | // ¹ÔËö¤Î/¤ò¼è¤ê½ü¤¯
|
|---|
| 223 | $dir = ereg_replace("/$", "", $dir);
|
|---|
| 224 | $path = $dir."/".$file;
|
|---|
| 225 | if ($file != '..' && $file != '.' && is_dir($path)) {
|
|---|
| 226 | return true;
|
|---|
| 227 | }
|
|---|
| 228 | }
|
|---|
| 229 | }
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | return false;
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | /*
|
|---|
| 236 | * ´Ø¿ô̾¡§lfIsFileOpen()
|
|---|
| 237 | * ÀâÌÀ¡¡¡§»ØÄꤷ¤¿¥Õ¥¡¥¤¥ë¤¬Á°²ó³«¤«¤ì¤¿¾õÂ֤ˤ¢¤Ã¤¿¤«¥Á¥§¥Ã¥¯
|
|---|
| 238 | * °ú¿ô1 ¡§¥Ç¥£¥ì¥¯¥È¥ê
|
|---|
| 239 | * °ú¿ô2 ¡§¸½ºß¤Î¥Ä¥ê¡¼¤Î¾õÂÖ³«¤¤¤Æ¤¤¤ë¥Õ¥©¥ë¥À¤Î¥Ñ¥¹¤¬ | ¶èÀÚ¤ê¤Ç³ÊǼ
|
|---|
| 240 | */
|
|---|
| 241 | function lfIsFileOpen($dir, $tree_status) {
|
|---|
| 242 | $arrTreeStatus = split('\|', $tree_status);
|
|---|
| 243 | if(in_array($dir, $arrTreeStatus)) {
|
|---|
| 244 | return true;
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | return false;
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | /*
|
|---|
| 251 | * ´Ø¿ô̾¡§sfDownloadFile()
|
|---|
| 252 | * °ú¿ô1 ¡§¥Õ¥¡¥¤¥ë¥Ñ¥¹
|
|---|
| 253 | * ÀâÌÀ¡¡¡§¥Õ¥¡¥¤¥ë¤Î¥À¥¦¥ó¥í¡¼¥É
|
|---|
| 254 | */
|
|---|
| 255 | function sfDownloadFile($file) {
|
|---|
| 256 | // ¥Õ¥¡¥¤¥ë¤Î¾ì¹ç¤Ï¥À¥¦¥ó¥í¡¼¥É¤µ¤»¤ë
|
|---|
| 257 | Header("Content-disposition: attachment; filename=".basename($file));
|
|---|
| 258 | Header("Content-type: application/octet-stream; name=".basename($file));
|
|---|
| 259 | Header("Cache-Control: ");
|
|---|
| 260 | Header("Pragma: ");
|
|---|
| 261 | echo (sfReadFile($file));
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | /*
|
|---|
| 265 | * ´Ø¿ô̾¡§sfCreateFile()
|
|---|
| 266 | * °ú¿ô1 ¡§¥Õ¥¡¥¤¥ë¥Ñ¥¹
|
|---|
| 267 | * °ú¿ô2 ¡§¥Ñ¡¼¥ß¥Ã¥·¥ç¥ó
|
|---|
| 268 | * ÀâÌÀ¡¡¡§¥Õ¥¡¥¤¥ëºîÀ®
|
|---|
| 269 | */
|
|---|
| 270 | function sfCreateFile($file, $mode = "") {
|
|---|
| 271 | // ¹ÔËö¤Î/¤ò¼è¤ê½ü¤¯
|
|---|
| 272 | if($mode != "") {
|
|---|
| 273 | $ret = @mkdir($file, $mode);
|
|---|
| 274 | } else {
|
|---|
| 275 | $ret = @mkdir($file);
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | return $ret;
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | /*
|
|---|
| 282 | * ´Ø¿ô̾¡§sfReadFile()
|
|---|
| 283 | * °ú¿ô1 ¡§¥Õ¥¡¥¤¥ë¥Ñ¥¹
|
|---|
| 284 | * ÀâÌÀ¡¡¡§¥Õ¥¡¥¤¥ëÆÉ¹þ
|
|---|
| 285 | */
|
|---|
| 286 | function sfReadFile($filename) {
|
|---|
| 287 | $str = "";
|
|---|
| 288 | // ¥Ð¥¤¥Ê¥ê¥â¡¼¥É¤Ç¥ª¡¼¥×¥ó
|
|---|
| 289 | $fp = @fopen($filename, "rb" );
|
|---|
| 290 | //¥Õ¥¡¥¤¥ëÆâÍÆ¤òÁ´¤ÆÊÑ¿ô¤ËÆÉ¤ß¹þ¤à
|
|---|
| 291 | if($fp) {
|
|---|
| 292 | $str = @fread($fp, filesize($filename)+1);
|
|---|
| 293 | }
|
|---|
| 294 | @fclose($fp);
|
|---|
| 295 |
|
|---|
| 296 | return $str;
|
|---|
| 297 | }
|
|---|
| 298 | ?>
|
|---|