megacolorboy

Back

Published on September 28th, 2020

Laravel

Clear a file directory using Filesystem in Laravel

I was working on a project that dealt with generating large .zip exports and as a result, the directory, which was used to store all the .zip exports, ended up going all the way up to a whopping size of 10 gigabytes! 😮I resolved it by calling the package in my controller:Then simply, create a new instance and define the directory you wanted to clear:Hope this helps you out!

1 minute read

I was working on a project that dealt with generating large .zip exports and as a result, the storage/exports directory, which was used to store all the .zip exports, ended up going all the way up to a whopping size of 10 gigabytes! 😮

I resolved it by calling the Filesystem package in my controller:


use Illuminate\Filesystem\Filesystem;

Then simply, create a new instance and define the directory you wanted to clear:


$folder = new Filesystem;
$folder->cleanDirectory('storage/exports');

Hope this helps you out!