Retrieving System Information With patSysinfo - Mounting Up
(Page 8 of 9 )
Finally, you can obtain information on mounted file system with the getMounts() method, which returns an array containing detailed information from both the "df" command and "/proc/mounts". Take a look:
<?php
// include class
include("patSysinfo.php");
// instantiate object
$sys = new patSysinfo();
// get mounted file systems
$mounts = $sys->getMount();
// output mount information
print_r($mounts); die;
? >
Here's what the output of this script might look like:
Array
(
[0] => Array
(
[disk] => /dev/hda3
[size] => 4.73 GByte
[used] => 923.00 MByte
[free] => 3.59 GByte
[percent] => 21
[mount] => /
[type] => ext2
)
[1] => Array
(
[disk] => /dev/hda2
[size] => 4.89 GByte
[used] => 346.95 MByte
[free] => 4.55 GByte
[percent] => 7
[mount] => /mnt/dos
[type] => vfat
)
[2] => Array
(
[disk] => /dev/hda4
[size] => 15.64 MByte
[used] => 1.79 MByte
[free] => 13.85 MByte
[percent] => 12
[mount] => /mnt/scamp
[type] => msdos
)
)
Of course, this isn't very useful by itself - what you really need to do is format it into a tabular representation, like this:
<html>
<head>
</head>
<body>
<table border="1" cellspacing="0" cellpadding="5">
<tr>
<td><u>Disk</u></td>
<td><u>Mount point</u></td>
<td><u>Type</u></td>
<td><u>Size</u></td>
<td><u>Used space</u></td>
<td><u>Free space</u></td>
<td><u>Used space %</u></td>
</tr>
<?php
// include class
include("patSysinfo.php");
// instantiate object
$sys = new patSysinfo();
// get mounted file systems
$mounts = $sys->getMount();
// output mount information
foreach($mounts as $m)
{
echo "<tr>";
echo "<td>" . $m['disk'] . "</td>";
echo "<td>" . $m['mount'] . "</td>";
echo "<td>" . $m['type'] . "</td>";
echo "<td>" . $m['size'] . "</td>";
echo "<td>" . $m['used'] . "</td>";
echo "<td>" . $m['free'] . "</td>";
echo "<td>" . $m['percent'] . " %</td>";
echo "</tr>";
}
? >
</body>
</html>
Here's the (much-friendlier) output:

Next: Link Zone >>
More PHP Articles
More By icarus, (c) Melonfire