How to get size of directory in MB Laravel 5?

By Hardik Savani | July 23, 2016 | | 42378 Viewer | Category : Laravel


Mostly we require to calculate for uploaded directory size because we can see how much we size allocate in uploaded directory. If you have limited server then you always need to check how much size of data in my folder.

You can also get size of directory that way you can also display on your admin panel. Laravel provide File facade. File facade through we can get folder size in kb or mb or gb etc.

In bellow example i have images directory in public folder. so we can get size for images folder like this way :

Example:

$file_size = 0;


foreach( File::allFiles(public_path('images')) as $file)

{

$file_size += $file->getSize();

}


$file_size = number_format($file_size / 1048576,2);

print_r($file_size.' MB');



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.


We are Recommending you: