mark107 Posted March 9, 2023 Share Posted March 9, 2023 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? Quote Link to comment Share on other sites More sharing options...
gw1500se Posted March 9, 2023 Share Posted March 9, 2023 You need to make sure your calculation is using the same units. You probably need to convert GB to MB or vice versa. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 9, 2023 Share Posted March 9, 2023 YOu are doing some math with bytes. But you are also trying to calculate something you are calling a 'width'. What is a width when you're looking at file and table sizes? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.