-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathstatistics.php
54 lines (52 loc) · 1.6 KB
/
statistics.php
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<?php
$path = getcwd();
walkDir($path);
echo "<h2>Path ; $path</h2><p>";
echo 'Number of <b>Files</b><br>';
echo var_dump($numfiles);
echo 'Number of <b>Lines of Code</b><br>';
echo var_dump($numlines);
echo 'Size in KBytes</b><br>';
echo var_dump($numsize);
exit;
?>
</head>
<body>
<?php
$numfiles = [];
$numlines = [];
$numsize = [];
function readSourceFile($file, $ext) {
global $numfiles, $numlines, $numsize;
$numfiles[$ext]++;
$numlines[$ext] += count(file($file));
$numsize[$ext] += floor(max(1, filesize($file) / 1024));
}
function walkDir($path) {
if (is_dir($path)) {
$dh = opendir($path);
while (($file = readdir($dh)) !== false) {
if ($file == '.' || $file == '..' || substr($file, 0, 1) == '.') {
continue;
}
if (is_dir($path . '/' . $file)) {
walkDir($path . '/' . $file);
}
$arr = explode('.', $file);
$ext = $arr[count($arr) - 1];
if (stripos(' php js css html ', $ext) > 0) {
readSourceFile($path . '/' . $file, $ext);
}
}
closedir($dh);
return;
}
}
?>
</body>
</html>