How To Check Occupied Disk Space In Laravel

In this tutorial I will give you example about how to check occupied disk space in laravel or check free RAM in server. Many time we need requirments to check occupied disk space of server in adminside dashboard and we are checking manually if disk space are fully occipied or not. So, In this tutorial I will explain you how to check occupied disk space in laravel so you can check directly in adminside without any manual action. Also you can use this code in ubuntu as well.

PHP provide built-in function to check total space and free space of server, here we will use disk_total_space() and disk_free_space() functions and will get output.

The disk_total_space() function returns the total size, in bytes, of the specified filesystem or disk.

Syntax :


The disk_free_space() function returns the free space, in bytes, of the specified filesystem or disk.



Syntax :



Example : 

 I have created one controller and created disk_occupied() function like below.

public function disk_occupied()
        $disktotal = disk_total_space('/'); //DISK usage
        $disktotalsize = $disktotal / 1073741824;

        $diskfree  = disk_free_space('/');
        $used = $disktotal - $diskfree;

        $diskusedize = $used / 1073741824;
        $diskuse1   = round(100 - (($diskusedize / $disktotalsize) * 100));
        $diskuse = round(100 - ($diskuse1)) . '%';
    return view('home',compact('diskuse','disktotalsize','diskusedize'));

Then after put below code in your home.blade.php file.

  <link href="" rel="stylesheet">
    <h3 class="no-margin text-semibold text-center">Occupied Disk Space - Techsolutionstuff</h3>
    <div class="col-sm-12 col-md-4 col-md-offset-4">    
        <div class="progress progress-micro mb-10">
          <div class="progress-bar bg-indigo-400" style="width: {{$diskuse}}">
            <span class="sr-only">{{$diskuse}}</span>
        <span class="pull-right">{{round($diskusedize,2)}} GB /
        {{round($disktotalsize,2)}} GB ({{$diskuse}})</span>       


And finally we will get output like below screenshot.

Occupied Disk Space

You might also like : 


Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.