Jump to content

PHP Total Diskspace on Server to Folder Disk space?.


dlex

Recommended Posts

Hey guys,

 

I am having small issues with my CMS which i am trying to include client disk space on the dashboard. Used and left.

 

I got the following code to work just fine but it's displaying the server total disk space instead of the "folder" disk space.

 

Is this possible?, we are using a server with Plesk. I would really appreciate if you could take a look at the code and correct it if possible..

 

<?php 
function size_readable($size, $max = null, $system = 'si', $retstring = '%01.0f %s')
{
    // Pick units
    $systems['si']['prefix'] = array('B', 'K', 'MB', 'GB', 'TB', 'PB');
    $systems['si']['size']   = 1000;
    $systems['bi']['prefix'] = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB');
    $systems['bi']['size']   = 1024;
    $sys = isset($systems[$system]) ? $systems[$system] : $systems['si'];

    // Max unit to display
    $depth = count($sys['prefix']) - 1;
    if ($max && false !== $d = array_search($max, $sys['prefix'])) {
        $depth = $d;
    }

    // Loop
    $i = 0;
    while ($size >= $sys['size'] && $i < $depth) {
        $size /= $sys['size'];
        $i++;
    }

    return sprintf($retstring, $size, $sys['prefix'][$i]);
}

$plass = getcwd();

$diskused = disk_free_space($plass);

$disktotal = disk_total_space($plass);

$plus = $disktotal;  
$minus = $diskused;  
  
$totalnumber = $plus + $minus;  
  
$pluspercent = round(($plus / $totalnumber) * 100);  
$minuspercent = round(($minus / $totalnumber) * 100);  
  
$total = round($plus + $minus);  
$totalVotes += $total;  
?>

Folders aren't limited on space...the amount of available space is limited by the partition it's on. Without looping over everything in the entire directory recursively, I can't think of a way.

 

Can you not setup a separate partition for each client? This is probably the better way to go anyways...so you can limit the amount of space on a per client basis, and one client eating up space won't affect others.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.