diff --git a/htdocs/app/Http/Controllers/JsonTransferController.php b/htdocs/app/Http/Controllers/JsonTransferController.php index 5cbcd500..37cf45dc 100644 --- a/htdocs/app/Http/Controllers/JsonTransferController.php +++ b/htdocs/app/Http/Controllers/JsonTransferController.php @@ -81,20 +81,19 @@ class JsonTransferController extends Controller return response()->download($file); } - public function downloadAll(){ - $zipFile = base_path('database/seeders/data/all_json.zip'); - $zip = new ZipArchive; - - 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(); + public function downloadAll() + { + $targetDir = base_path('database/seeders/data/'); + $zipFile = $targetDir . 'all_json.zip'; + if (file_exists($zipFile)) { + File::delete($zipFile); } - - return response()->download($zipFile); + $command = "cd {$targetDir} && zip -r all_json.zip ."; + shell_exec($command); + if (file_exists($zipFile)) { + return response()->download($zipFile); + } + return back()->with('error', 'Gagal membuat file ZIP.'); } public function importTable($table) {