If the web hosting is using cPanel then you can use the cPanel API to call the getFreeSpace() and getSpaceUsed() function.
function getFreeSpace()
{
$freeSpace = $this->parseIndex('Disk space available', 'float');
return ($freeSpace == 0) ? 'Unlimited' : floatval($freeSpace);
}
Just my 2 penny
cPanel API: "cPanel URL"
Update:
I came across the web and found this php script (extracted from a cms plugin). So this is the script that I have tested on my web hosting:
<?php
// SETTINGS - START
// PUT YOUR CPANEL HOSTING USERNAME HERE:
$username = "username";
// PUT YOUR CPANEL HOSTING USERNAME HERE:
$password = "password";
// MODIFY THIS PATH TO REFLECT YOUR DOMAIN, REPLACING "DOMAIN-NAME" AND "YOUR-CPANEL-USERNAME":
$query ="http://cpanel.yoursite.com:2082/xml-api/cpanel?user=USERNAME&cpanel_xmlapi_module=StatsBar&cpanel_xmlapi_func=stat&display=diskusage";
// SETTINGS - END
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curl, CURLOPT_HEADER,0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_USERPWD, $username.":".$password);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
curl_close($curl);
$xml = simpleXML_load_string($result);
$df = $xml->data[0]->_count; // used MB
$ds = $xml->data[0]->_max; // max MB
$du = $ds - $df; // free MB
if ($ds > 0) $perc = number_format(100 * $du / $ds, 2); else $perc = 0;
$color = '#e87d7d';
if ($perc > 50) $color = '#e8cf7d';
if ($perc > 70) $color = '#ace97c';
echo '<li style="font-weight:bold;padding:5px 15px;border-radius:4px;-moz-border-radius:4px;-webkit-border-radius:4px;background-color:#182227;margin-left:13px;color:#afc5cf;">'
.'Free disk space'
.'<div style="border:1px solid #ccc;width:100%;margin:2px 5px 2px 0;padding:1px">'
.'<div style="width:'.$perc.'%;background-color:'.$color.';height:6px"></div></div>'
.$du.' of '.$ds.' MB free'.'</li>';
?>
Source script: http://get-simple.info/extend/plugin/free-disk-space-cpanel/317/