Jump to content

[SOLVED] two functions not working at the same time


lewis987

Recommended Posts

basically to functions to get the free size left on the hard-drive and another to get the total space on it. code below.

 

$dir = $server1['data'];
$size = disk_total_space($dir);
function formatTotal($size){
    switch (true){
    case ($size > 1048576):
        $size /= 1048576;
        $suffix = 'MB';    
    break;
    case ($size > 1024):
        $size /= 1024;
        $suffix = 'KB';
        break;
    default:
        $suffix = 'B';
    }
    return round($size, 2).$suffix;
}

$goose = disk_free_space($dir);
function zz($goose){
    switch (true){
    case ($size > 1048576):
        $size /= 1048576;
        $suffix = 'MB';    
    break;
    case ($size > 1024):
        $size /= 1024;
        $suffix = 'KB';
        break;
    default:
        $suffix = 'B';
    }
    return round($size, 2).$suffix;
}

 

if i echo $goose it shows the space in bytes but i want it to show it in MB or KB depending on the size. Im on PHP 4.4.9 (i believe). Basically its when i cann formatTotal it shows the total space (that one works fine) but when i call "zz" it just shows me "0B" and when i show $goose i get the proper size in bytes.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.