Update pengelolaan file banyak dokumen di DokumenJaminanController
Memperbarui logika untuk penanganan beberapa file dokumen jaminan dalam satu entri database. Sebelumnya hanya satu file yang ditangani, kini mendukung array file untuk setiap entri. Penambahan ini memastikan semua file dari entri dokumen jaminan terangkut dan memperbaiki masalah saat file tidak ditemukan.
This commit is contained in:
@@ -378,12 +378,16 @@
|
||||
|
||||
if ($zip->open($zipFilePath, ZipArchive::CREATE) === true) {
|
||||
foreach ($documents as $document) {
|
||||
$filePath = storage_path('app/public/' . $document->dokumen_jaminan);
|
||||
if (file_exists($filePath)) {
|
||||
$zip->addFile($filePath, basename($filePath));
|
||||
} else {
|
||||
// Log or display an error message for missing files
|
||||
return redirect()->back()->with('error', 'File not found: ' . $filePath);
|
||||
$files = is_array(json_decode($document->dokumen_jaminan)) ? json_decode($document->dokumen_jaminan) : [$document->dokumen_jaminan];
|
||||
|
||||
foreach ($files as $file) {
|
||||
$filePath = storage_path('app/public/' . $file);
|
||||
if (file_exists($filePath)) {
|
||||
$zip->addFile($filePath, basename($filePath));
|
||||
} else {
|
||||
// Log or display an error message for missing files
|
||||
return redirect()->back()->with('error', 'File not found: ' . $filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
|
||||
Reference in New Issue
Block a user