Jump to content

Calculate on the disk size to make percentage


mark107

Recommended Posts

Hi all,

I need your help with my PHP coding. I'm working on the snippet to calculating on the two folders and the database to get the used size, then I'm calculating on the used size with the percent to make the width size.

<?php

//Connect to the database
require_once('../config.php');

$db_name = "db_user";
$mailbox = $link->prepare("SELECT table_schema,SUM( data_length + index_length ) / 1024 AS dbsize FROM information_schema.TABLES WHERE table_schema = '$db_name'");
$mailbox->execute();
$data = $mailbox->fetch(PDO::FETCH_ASSOC);
$db_size = $data['dbsize'];


$SIZE_LIMIT = 1073741824; // 1 GB
$upload_folder = foldersize('../uploads/');
$attachments_folder = foldersize('../u/attachments/');

$bytes = $upload_folder +  $attachments_folder;
$disk_used = $bytes + $db_size;
$disk_remaining = $SIZE_LIMIT - $disk_used;

$free_space = convertToReadableSize($disk_remaining);
$total = $SIZE_LIMIT;
$free = $SIZE_LIMIT - $disk_used;

$percentage = ($free / $total) * 100;
$width_size = 100 - round($percentage);

echo "width_size.............." . $width_size . '%';



?>

 

I want to make the width size with percent that start from 0% to 100% when I calculate on the two folders and the database to get the disk size and then calculate on the percent. On my code, it show that I have used 8% of the disk size when the disk used size is 144MB and the limit size I can use is 1GB. I'm not sure if I have wrote the code correctly.

Is that the correct way to calculate to make the total size and take away the disk used size then work out the percent or if I have done it wrong?

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.