فهرست منبع

more debug information for file upload

ljoaquim 1 هفته پیش
والد
کامیت
ed8d37addf
2فایلهای تغییر یافته به همراه34 افزوده شده و 2 حذف شده
  1. 5 0
      controllers/DocumentUploadController.php
  2. 29 2
      services/DocumentStorageService.php

+ 5 - 0
controllers/DocumentUploadController.php

@@ -153,6 +153,11 @@ class DocumentUploadController
 
             return ResponseLib::sendOk($created, 'S_CREATED');
         } catch (\Throwable $e) {
+            $this->log($requestId, 'upload failed', [
+                'user_id' => $userId,
+                'company_id' => $companyId,
+                'error' => $e->getMessage(),
+            ]);
             return ResponseLib::sendFail('Upload failed: ' . $e->getMessage(), [], 'E_INTERNAL')->withStatus(500);
         }
     }

+ 29 - 2
services/DocumentStorageService.php

@@ -35,7 +35,27 @@ class DocumentStorageService
 
         if (!is_dir($dir)) {
             if (!@mkdir($dir, 0775, true) && !is_dir($dir)) {
-                throw new \RuntimeException('Failed to create documents directory');
+                $lastError = error_get_last();
+                $root = rtrim($this->rootDir, '/');
+                $rootParent = dirname($root);
+
+                $debug = [
+                    'root_dir' => $root,
+                    'root_dir_exists' => is_dir($root),
+                    'root_dir_writable' => is_writable($root),
+                    'root_parent' => $rootParent,
+                    'root_parent_exists' => is_dir($rootParent),
+                    'root_parent_writable' => is_writable($rootParent),
+                    'target_dir' => $dir,
+                    'target_parent' => dirname($dir),
+                    'target_parent_exists' => is_dir(dirname($dir)),
+                    'target_parent_writable' => is_writable(dirname($dir)),
+                    'php_user' => get_current_user(),
+                    'euid' => function_exists('posix_geteuid') ? posix_geteuid() : null,
+                    'last_error' => $lastError,
+                ];
+
+                throw new \RuntimeException('Failed to create documents directory: ' . json_encode($debug, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
             }
         }
 
@@ -64,7 +84,14 @@ class DocumentStorageService
 
         $bytes = @file_put_contents($path, $content, LOCK_EX);
         if ($bytes === false) {
-            throw new \RuntimeException('Failed to write file');
+            $lastError = error_get_last();
+            $debug = [
+                'path' => $path,
+                'dir_exists' => is_dir($dir),
+                'dir_writable' => is_writable($dir),
+                'last_error' => $lastError,
+            ];
+            throw new \RuntimeException('Failed to write file: ' . json_encode($debug, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
         }
 
         return $path;