How To Check Occupied Disk Space In Laravel

WebSolutionStuff | Jul-29-2020 | Categories : Laravel

Many time we need requirments to check occupied disk space of server in adminside 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 these functions and will get output.

So, first you need to create Controller for logical part.

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

public function disk_total_demo()
        $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('details',compact('diskuse','disktotalsize','diskusedize'));

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

  <link href="" rel="stylesheet">
  <div class="col-sm-6 col-md-3">
    <h2 class="no-margin text-semibold">Occupied Disk Space</h2>
    <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


Recommended Post
Featured Post

Follow us
facebooklogo github instagram twitter