From b5af8a8d615309adcde9a1ff6777a4867fd16c8d Mon Sep 17 00:00:00 2001 From: lizhuoran <625237490@qq.com> Date: Thu, 12 Mar 2026 16:30:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E4=B8=B4=E6=97=B6=E7=9B=AE=E5=BD=95=E6=9D=83?= =?UTF-8?q?=E9=99=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在设置 PHPWord 临时目录前先创建目录 - 确保临时目录存在并具有正确的权限(0755) - 修复服务器环境下 tempnam() 权限错误 --- app/Services/DocumentPreviewService.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Services/DocumentPreviewService.php b/app/Services/DocumentPreviewService.php index 9d6a558..8ea9f4b 100644 --- a/app/Services/DocumentPreviewService.php +++ b/app/Services/DocumentPreviewService.php @@ -80,8 +80,12 @@ class DocumentPreviewService // 获取文件的完整路径 $filePath = Storage::disk('local')->path($document->file_path); - // 设置 PHPWord 的临时目录 - Settings::setTempDir(storage_path('app/temp')); + // 确保临时目录存在并设置 PHPWord 的临时目录 + $tempDir = storage_path('app/temp'); + if (!is_dir($tempDir)) { + mkdir($tempDir, 0755, true); + } + Settings::setTempDir($tempDir); // 加载 Word 文档 $phpWord = IOFactory::load($filePath);