Interest work
-
Declared the function of providing information on the area in the catalogue (Out space, free and how many).
Using this:
Wo_GetDisk("директория", "тип вывода (total, free, occupied)", "отображать ли данные в процентах (true / false)").
If, in the last argument, the function is false, the data shall be in such a format: 1024 MB/GB/KB - No problem with that.
If true, percentage.
But the problem is, I don't know how to provide the same information, only as a percentage - 25% - Used, for example, or freely (dependent on the meaning of the second argument (total, free, occupied)).
(I can imagine an abstract code that needs to be written to make it work, but in practice nothing works out. If someone thought it was useful, take it. Though I think I made another bike.
The miracle function itself:
function Wo_GetDisk($dir, $type, $percent) { /* * Wo_SizeFormat - переводит байты в понятный нам формат (GB, KB...) (Санитайзит вывод) * PATH - Константа абсолютного пути ($_SERVER['DOCUMENT_ROOT']) */ if (isset($type) && isset($dir) && isset($percent)) { if (!empty($type) && !empty($dir) && !empty($percent)) { $free = disk_free_space(PATH . $dir); $total = disk_total_space(PATH . $dir); $occupied = $total - $free;
switch ($type) { case "total": { if ($percent === true) { return "Total в процетах..."; } else { return Wo_SizeFormat($total); } } case "free": { if ($percent === true) { return "Free в процетах..."; } else { return Wo_SizeFormat($free); } } case "occupied": { if ($percent === true) { return "Occupied в процетах..."; } else { return Wo_SizeFormat($occupied); } } default: { return null; } } } }
}
-
Show free space: $percent = $free * 100 / $total;
Show a busy space: $percent = 100 - $free * 100 / $total ;