Jump to content

Convert an array bytes to MB PHP


Penwell

Recommended Posts

I have this php file which i use to get downloaded and uploaded data usage from my splynx radius server over API which outputs it as bytes making a very long string which i want to shorten into Mbps and from the arrays that i get from splynx server i would like help to convert the array "in_bytes" and "out_bytes" to MB. This is my whole code below. currently the output is in bytes and i need it to be in MB

<?php

$api_url = 'https://xxx/'; // Splynx URL

$admin_login = "xxx"; // administrator login
$admin_password = "xxx"; // administrator password

$api = new SplynxAPI($api_url);
$api->setVersion(SplynxApi::API_VERSION_2);

$isAuthorized = $api->login([
    'auth_type' => SplynxApi::AUTH_TYPE_ADMIN,
    'login' => $admin_login,
    'password' => $admin_password,
]);

if (!$isAuthorized) {
    exit("Authorization failed!\n");
}

$customerApiUrl_online = "admin/customers/customers-online";

$customers_params = [
    'main_attributes' => [
        'status' => ['IN', ['active', 'blocked']]
    ]];

$result_online = $api->api_call_get($customerApiUrl_online);
$customers_online = $api->response;
?>

<table class="table table-transparent">
    <thead>
        <tr>
            <th>DOWNOAD</th>
            <th>UPLOAD</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach($customers_online as $item) :?>
            <tr>
                <td><?php echo $item['in_bytes']; ?></td>
                <td><?php echo $item['out_bytes']; ?></td>
            </tr>
        <?php endforeach;?>
    </tbody>
</table>

 

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.