-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathView.class.php
More file actions
108 lines (101 loc) · 2.9 KB
/
View.class.php
File metadata and controls
108 lines (101 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* 共通ファイル操作クラス(View)
*
* @package NetCommons.component
* @author Noriko Arai,Ryuji Masukawa
* @copyright 2006-2007 NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @project NetCommons Project, supported by National Institute of Informatics
* @access public
*/
class File_View {
var $_className = "File_View";
/**
* ファイルサイズ取得
* @param string $path 対象パス
* @return int ファイルサイズ (失敗:false)
**/
function getSize($path){
if (!is_dir($path))
return filesize($path);
$size=0;
$handle = opendir($path);
while ( false !== ($file = readdir($handle)) ) {
if ($file=='.' or $file=='..')
continue;
if ( $file == 'CVS' || strtolower($file) == '.svn') { continue; }
$size+=$this->getSize($path.'/'.$file);
}
closedir($handle);
return $size;
}
/**
* 指定パスにあるディレクトリ一覧を返す関数
*
* @param string $path 対象パス
* @return array array:正常,false:異常
**/
function getCurrentDir($path) {
if ( is_dir($path) ) {
$dir_list = array();
$handle = opendir($path);
while ( false !== ($file = readdir($handle)) ) {
if ( $file == '.' || $file == '..' ) { continue; }
if ( $file == 'CVS' || strtolower($file) == '.svn') { continue; }
if ( is_dir($path. "/". $file) ) {
$dir_list[] = $file;
}
}
closedir($handle);
return $dir_list;
} else {
return false;
}
}
/**
* 指定パスにあるファイル一覧を返す関数
*
* @param string $path 対象パス
* @return array array:正常,false:異常
**/
function getCurrentFiles($path) {
if ( is_dir($path) ) {
$files_list = array();
$handle = opendir($path);
while ( false !== ($file = readdir($handle)) ) {
if ( $file == '.' || $file == '..' ) { continue; }
if ( $file == 'CVS' || strtolower($file) == '.svn') { continue; }
if ( !is_dir($path. "/". $file) ) {
$files_list[] = $file;
}
}
closedir($handle);
return $files_list;
} else {
return false;
}
}
/**
* 単位付きのサイズに変換し返す
* @param float $size(size)
* @param int $precision(小数点いくつまで表示するか(default:小数点1位まで))
* @return string
* @access public
*/
function formatSize($size, $precision=1) {
$UnitArray = array("", "K", "M", "G", "T");
//$UnitArray = array("", "Ki", "Mi", "Gi", "Ti");
$Byte = 1024;
foreach ($UnitArray as $val) {
if ($size < $Byte) break;
$size = $size / $Byte;
}
if ($size < 100 && $val != $UnitArray[0]) {
return round($size, $precision). $val;
} else {
return round($size). $val;
}
}
}
?>