Perbaiki proses penambahan file ke dalam zip
Tambahkan pengecekan eksistensi 'dokumen_jaminan' sebelum memproses penambahan file ke dalam arsip zip untuk mencegah error. Hal ini menghindari kasus di mana dokumen_jaminan tidak ada atau null.
This commit is contained in:
@@ -392,17 +392,19 @@
|
||||
|
||||
if ($zip->open($zipFilePath, ZipArchive::CREATE) === true) {
|
||||
foreach ($documents as $document) {
|
||||
$files = is_array(json_decode($document->dokumen_jaminan)) ? json_decode(
|
||||
$document->dokumen_jaminan,
|
||||
) : [$document->dokumen_jaminan];
|
||||
if($document->dokumen_jaminan) {
|
||||
$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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user