ใช้ PHP + HTML เพื่อตรวจสอบ “เนื้อที่เหลือใน CentOS 9” (Disk Free Space)


หากคุณต้องการใช้ PHP + HTML เพื่อตรวจสอบ “เนื้อที่เหลือใน CentOS 9” (Disk Free Space) สามารถใช้ฟังก์ชัน disk_free_space() หรือรันคำสั่ง shell ผ่าน shell_exec() ได้ดังนี้:

ใช้ disk_free_space() และ disk_total_space()

<?php
$path = "/"; // root directory

$free = disk_free_space($path);
$total = disk_total_space($path);

$free_gb = round($free / 1024 / 1024 / 1024, 2);
$total_gb = round($total / 1024 / 1024 / 1024, 2);
$used_gb = $total_gb - $free_gb;
$used_percent = round(($used_gb / $total_gb) * 100, 2);
?>

<!DOCTYPE html>
<html>
<head>
    <title>ตรวจสอบเนื้อที่</title>
</head>
<body>
    <h1>ตรวจสอบเนื้อที่บน CentOS 9</h1>
    <p>รวมทั้งหมด: <?= $total_gb ?> GB</p>
    <p>ใช้ไปแล้ว: <?= $used_gb ?> GB (<?= $used_percent ?>%)</p>
    <p>คงเหลือ: <?= $free_gb ?> GB</p>
</body>
</html>
, , ,