diff --git a/gestion/lib/Service/InvoicePdfService.php b/gestion/lib/Service/InvoicePdfService.php index cbbdf34..cdcf8bf 100644 --- a/gestion/lib/Service/InvoicePdfService.php +++ b/gestion/lib/Service/InvoicePdfService.php @@ -602,6 +602,9 @@ class InvoicePdfService $filenames = []; foreach ($factureFolders as $folder) { + // Créer le chemin complet étape par étape + $this->ensurePathExists($storage, $folder); + $ff_pdf = $folder . $pdfFilename . '.pdf'; try { @@ -613,6 +616,8 @@ class InvoicePdfService $file_pdf->putContent($pdfContent); $filenames[] = $ff_pdf; } catch (\Throwable $e) { + // Supprimez ce var_dump pour éviter l'erreur de headers + // var_dump("yyyyyyyyyyyyyyyyyyyy".$e->getMessage()); error_log("ERROR on file '$ff_pdf': " . $e->getMessage()); continue; } @@ -620,4 +625,26 @@ class InvoicePdfService return $filenames; } + + private function ensurePathExists($storage, $path) + { + $parts = explode('/', trim($path, '/')); + $currentPath = ''; + + foreach ($parts as $part) { + if (empty($part)) { + continue; + } + + $currentPath .= '/' . $part; + + try { + if (!$storage->nodeExists($currentPath)) { + $storage->newFolder($currentPath); + } + } catch (\Throwable $e) { + error_log("Cannot create folder '$currentPath': " . $e->getMessage()); + } + } + } }