This commit is contained in:
Dwi Swandhana
2026-08-20 06:17:59 +07:00
parent e974c2a57c
commit 997a0fe192
@@ -81,20 +81,19 @@ class JsonTransferController extends Controller
return response()->download($file); return response()->download($file);
} }
public function downloadAll(){ public function downloadAll()
$zipFile = base_path('database/seeders/data/all_json.zip'); {
$zip = new ZipArchive; $targetDir = base_path('database/seeders/data/');
$zipFile = $targetDir . 'all_json.zip';
File::delete($zipFile); if (file_exists($zipFile)) {
File::delete($zipFile);
if ($zip->open($zipFile, ZipArchive::CREATE) === TRUE) {
foreach (File::files(base_path($this->exportPath)) as $file) {
$zip->addFile($file->getRealPath(), basename($file));
}
$zip->close();
} }
$command = "cd {$targetDir} && zip -r all_json.zip .";
return response()->download($zipFile); shell_exec($command);
if (file_exists($zipFile)) {
return response()->download($zipFile);
}
return back()->with('error', 'Gagal membuat file ZIP.');
} }
public function importTable($table) { public function importTable($table) {