added clean temp files schedule
This commit is contained in:
43
app/Console/Commands/CleanupTempFiles.php
Normal file
43
app/Console/Commands/CleanupTempFiles.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class CleanupTempFiles extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:cleanup-temp-files';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Delete temporary files that are older that 1 day';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$keepTime = 1 * 24 * 60 * 60; // 1 Day
|
||||
$currentTimeStamp = time();
|
||||
$deletedFileCount = 0;
|
||||
|
||||
foreach (glob(storage_path('app/tmp/*')) as $filename) {
|
||||
$fileModifiedTimeStamp = filemtime($filename);
|
||||
if($currentTimeStamp - $fileModifiedTimeStamp > $keepTime) {
|
||||
unlink($filename);
|
||||
$deletedFileCount++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->comment('Deleted ' . $deletedFileCount . ' files');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user