55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Utilities;
|
|
|
|
use App\Console\Commands\Grapper\Sofascore;
|
|
use RecursiveDirectoryIterator;
|
|
use RecursiveIteratorIterator;
|
|
use ZipArchive;
|
|
|
|
class ZipFolder
|
|
{
|
|
public static function create(string $day){
|
|
|
|
$zipFilePath = storage_path('zip_sofascore_data').'/'.$day.'.zip';
|
|
|
|
$path = Sofascore::$grapper_path.$day;
|
|
|
|
$zip = new ZipArchive();
|
|
|
|
if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true) {
|
|
|
|
if(is_dir($path)){
|
|
|
|
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
|
|
|
|
foreach ($files as $file) {
|
|
if (!$file->isDir()) {
|
|
$filePath = $file->getRealPath();
|
|
$relativePath = substr($filePath, strlen($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;
|
|
}
|
|
}
|