-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.php
26 lines (25 loc) · 886 Bytes
/
stats.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
<?php
$dir = "up/";
$fi = new FilesystemIterator($dir, FilesystemIterator::SKIP_DOTS);
$files = iterator_count($fi);
$size = getDirectorySize($dir);
$format = formatBytes($size);
function getDirectorySize($dir) {
$bytestotal = 0;
$path = realpath($dir);
if (file_exists($path)) {
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) {
$bytestotal += $object->getSize();
}
}
return $bytestotal;
}
function formatBytes($size, $precision = 2) {
$base = log($size, 1024);
$suffixes = array('B', 'KB', 'MB', 'GB', 'TB');
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
}
header("Content-Type: application/json; charset=utf-8");
header("Cloudflare-CDN-Cache-Control: max-age=600");
echo "{\"file\":$files,\"sizebytes\":$size,\"size\":\"$format\"}";
exit();