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) {
|
if ($zip->open($zipFilePath, ZipArchive::CREATE) === true) {
|
||||||
foreach ($documents as $document) {
|
foreach ($documents as $document) {
|
||||||
$files = is_array(json_decode($document->dokumen_jaminan)) ? json_decode(
|
if($document->dokumen_jaminan) {
|
||||||
$document->dokumen_jaminan,
|
$files = is_array(json_decode($document->dokumen_jaminan)) ? json_decode(
|
||||||
) : [$document->dokumen_jaminan];
|
$document->dokumen_jaminan,
|
||||||
|
) : [$document->dokumen_jaminan];
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
$filePath = storage_path('app/public/' . $file);
|
$filePath = storage_path('app/public/' . $file);
|
||||||
if (file_exists($filePath)) {
|
if (file_exists($filePath)) {
|
||||||
$zip->addFile($filePath, basename($filePath));
|
$zip->addFile($filePath, basename($filePath));
|
||||||
} else {
|
} else {
|
||||||
// Log or display an error message for missing files
|
// Log or display an error message for missing files
|
||||||
return redirect()->back()->with('error', 'File not found: ' . $filePath);
|
return redirect()->back()->with('error', 'File not found: ' . $filePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user