فهرست منبع

test fix to upload

ljoaquim 1 هفته پیش
والد
کامیت
c104fab0d8
1فایلهای تغییر یافته به همراه14 افزوده شده و 8 حذف شده
  1. 14 8
      libs/MultipartFormDataParser.php

+ 14 - 8
libs/MultipartFormDataParser.php

@@ -9,14 +9,6 @@ class MultipartFormDataParser
     public static function parse(ServerRequestInterface $request): array
     {
         $contentType = $request->getHeaderLine('Content-Type');
-        if (!preg_match('/multipart\/form-data;\s*boundary=(?:(?:"([^"]+)")|([^;\s]+))/i', $contentType, $m)) {
-            throw new \RuntimeException('Invalid multipart Content-Type');
-        }
-
-        $boundary = (isset($m[1]) && $m[1] !== '') ? $m[1] : ($m[2] ?? '');
-        if ($boundary === '') {
-            throw new \RuntimeException('Missing multipart boundary');
-        }
 
         $rawBody = '';
         $stream = $request->getBody();
@@ -60,6 +52,20 @@ class MultipartFormDataParser
             $rawBody = (string)file_get_contents('php://input');
         }
 
+        return self::parseBody($contentType, $rawBody, $streamMeta);
+    }
+
+    public static function parseBody(string $contentType, string $rawBody, array $streamMeta = []): array
+    {
+        if (!preg_match('/multipart\/form-data;\s*boundary=(?:(?:"([^"]+)")|([^;\s]+))/i', $contentType, $m)) {
+            throw new \RuntimeException('Invalid multipart Content-Type');
+        }
+
+        $boundary = (isset($m[1]) && $m[1] !== '') ? $m[1] : ($m[2] ?? '');
+        if ($boundary === '') {
+            throw new \RuntimeException('Missing multipart boundary');
+        }
+
         $delimiter = "--" . $boundary;
         $parts = explode($delimiter, $rawBody);