How to Get Size of Directory in MB 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 use in laravel 6, laravel 7 and laravel 8 application.
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 :
$file_size = 0;
foreach( File::allFiles(public_path('images')) as $file)
$file_size += $file->getSize();
$file_size = number_format($file_size / 1048576,2);
I hope it cab help you...
- Laravel Eloquent inRandomOrder() Method Example
- Laravel Eloquent whereRaw Condition Example
- Laravel Move File from One Folder to Another Example
- Laravel Copy File from One Folder to Another Example
- Laravel Eager Loading with Count Relationship Example
- How to Get File Size from URL in Laravel?
- How to use soft delete in Laravel?
- Laravel Create and Download Zip File Example using chumper/zipper
- Laravel - How to count number of files in folder and remove all files in folder example?
- How to create a text file for JSON and file download in Laravel?