php - Check the free space for a user on web hosting -


i want check free space left on server (using hosting service). however, don't want know size of whole disc, account accidentally on. want know, have used 456 mb 1 gb of bought space.

i have tried use code answer (hosting account free space), let me cite it:

$free = disk_free_space("/"); $total = disk_total_space("/"); $percent = ($free/$total) * 100; echo $percent; 

there problem, however. @ first give me whole free space on real device. have 1gb space on hosting, , solution tells me have 202 gb free. btw, don't understand why question closed. maybe not clear, problem exists , accepted answer little wrong in opinion.

i have in mind solution using exec() , bash function, question is: is possible using php, without using exec()? exec() blocked, , should avoided due code verification problems. of course, example mysqldump() should run using exec(), 1 of few exceptions.

possible idea: though summing files on server, , in kind of config.php file enter account space manually. 1 solve problem, not in "nice" way. if buys 1 gb more, , forget config "constant".

if web hosting using cpanel can use cpanel api call getfreespace() , getspaceused() function.

function getfreespace() {     $freespace = $this->parseindex('disk space available', 'float');     return ($freespace == 0) ? 'unlimited' : floatval($freespace); } 

just 2 penny

cpanel api: http://www.phpkode.com/source/s/cpanel-api/cpanel-api/cpanel.php

update:

i came across web , found php script (extracted cms plugin). script have tested on web hosting:

disk space script

<?php    // settings - start  // put cpanel hosting username here:     $username = "username";  // put cpanel hosting username here:     $password = "password";  // modify path reflect domain, replacing "domain-name" , "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/


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -