From dedb18a80c932b1c98798f25b71cabd08de532c3 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Thu, 22 Oct 2026 21:06:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(wms):=20split=5Fexcel=20=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E4=B8=8D=E5=8F=AF=E5=86=99=E6=97=B6=E7=BB=99?= =?UTF-8?q?=E5=87=BA=E5=8F=AF=E6=89=A7=E8=A1=8C=E7=9A=84=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现象:返回 "fopen(.../public/export/xxx.xlsx): failed to open stream: Permission denied"。 public/export 目录属主/权限不允许 PHP 运行用户写入。 改动: - 目录不存在时 mkdir(0777);不可写时先 @chmod(0777) 尝试自愈 - 仍不可写则返回明确信息:目录、属主、权限、PHP 运行用户,并附带 chown -R www:www && chmod -R 775 的修复命令 - posix 信息获取做 is_array 保护,避免取不到用户时再抛 notice Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- application/index/controller/wms/Wms.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/application/index/controller/wms/Wms.php b/application/index/controller/wms/Wms.php index 81006a6..197777b 100644 --- a/application/index/controller/wms/Wms.php +++ b/application/index/controller/wms/Wms.php @@ -7679,7 +7679,20 @@ class Wms extends Frontend $exportDir = "{$rootpath}/../../../public/export"; if(!is_dir($exportDir)){ - mkdir($exportDir, 0755, true); + @mkdir($exportDir, 0777, true); + } + if(!is_writable($exportDir)){ + @chmod($exportDir, 0777); + } + if(!is_writable($exportDir)){ + $perm = substr(sprintf('%o', @fileperms($exportDir)), -4); + $ownerInfo = function_exists('posix_getpwuid') ? @posix_getpwuid(@fileowner($exportDir)) : null; + $userInfo = function_exists('posix_geteuid') ? @posix_getpwuid(posix_geteuid()) : null; + $owner = is_array($ownerInfo) ? $ownerInfo['name'] : 'unknown'; + $user = is_array($userInfo) ? $userInfo['name'] : 'unknown'; + $msg = "导出目录不可写:{$exportDir}(属主 {$owner},权限 {$perm},PHP 运行用户 {$user})"; + \think\Log::error('[split_excel] ' . $msg); + return json(['status'=>'error','msg'=>$msg.',请在服务器执行:chown -R www:www '.$exportDir.' && chmod -R 775 '.$exportDir]); } $filePath = "{$exportDir}/{$millisecondTimestamp}.xlsx"; $url = "https://ye4s.wms.gztbyc.com/export/{$millisecondTimestamp}.xlsx";