Ver Fonte

优化合并 pdf 功能

yemeishu há 11 horas atrás
pai
commit
4787858e18
1 ficheiros alterados com 22 adições e 0 exclusões
  1. 22 0
      app/Services/ExamPdfExportService.php

+ 22 - 0
app/Services/ExamPdfExportService.php

@@ -48,6 +48,17 @@ class ExamPdfExportService
 
         // 生成PDF文件(用于合并,不上传云存储)
         $pdfPath = storage_path("app/public/exams/{$paperId}_exam.pdf");
+        $examsDir = storage_path("app/public/exams");
+
+        // 【修复】确保exams目录存在
+        if (!is_dir($examsDir)) {
+            Log::info('ExamPdfExportService: 创建exams目录', ['path' => $examsDir]);
+            if (!mkdir($examsDir, 0755, true)) {
+                Log::error('ExamPdfExportService: 创建exams目录失败', ['path' => $examsDir]);
+                return null;
+            }
+        }
+
         Log::info('ExamPdfExportService: 开始生成试卷PDF', ['path' => $pdfPath, 'url' => $pageUrl]);
         $pdfBinary = $this->buildPdfFromUrl($pageUrl);
         if (!$pdfBinary) {
@@ -88,6 +99,17 @@ class ExamPdfExportService
 
         // 生成PDF文件(用于合并,不上传云存储)
         $pdfPath = storage_path("app/public/exams/{$paperId}_grading.pdf");
+        $examsDir = storage_path("app/public/exams");
+
+        // 【修复】确保exams目录存在
+        if (!is_dir($examsDir)) {
+            Log::info('ExamPdfExportService: 创建exams目录', ['path' => $examsDir]);
+            if (!mkdir($examsDir, 0755, true)) {
+                Log::error('ExamPdfExportService: 创建exams目录失败', ['path' => $examsDir]);
+                return null;
+            }
+        }
+
         Log::info('ExamPdfExportService: 开始生成判卷PDF', ['path' => $pdfPath, 'url' => $pageUrl]);
         $pdfBinary = $this->buildPdfFromUrl($pageUrl);
         if (!$pdfBinary) {