grap zip mail

This commit is contained in:
salam committed 2026-06-30 18:40:45 +02:00
1 parent 5081ec9e32
commit dfed73b228
18 files changed
+484 -188

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
<?php
namespace App\Utilities;
use App\Console\Commands\Grapper\Sofascore\Special;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use ZipArchive;
class ZipFolder
{
public static function create(string $day){
$zipFilePath = Special::$storage_path.'/'.$day.'.zip';
Special::$source_path .= '/'.$day;
$zip = new ZipArchive();
if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true) {
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(Special::$source_path));
foreach ($files as $file) {
if (!$file->isDir()) {
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen(Special::$source_path) + 1);
$zip->addFile($filePath, $relativePath);
}
}
$zip->close();
} else {
return response()->json(['error' => 'Failed to create ZIP archive'], 500);
}
}
public static function get_tree(string $dir, &$results = array()){
$files = scandir($dir);
foreach($files as $value){
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
if(!is_dir($path)) {
$results[] = $path;
} else if($value != "." && $value != "..") {
self::get_tree($path, $results);
$results[] = $path;
}
}
return $results;
}
}