From 0bc0b967d31f106e8b235a85861800b70c030b44 Mon Sep 17 00:00:00 2001 From: maztch Date: Thu, 4 Apr 2024 12:56:51 +0200 Subject: [PATCH] fix content-disposition --- src/Ilovepdf.php | 5 +++-- src/Task.php | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Ilovepdf.php b/src/Ilovepdf.php index d761c19..7281bd6 100644 --- a/src/Ilovepdf.php +++ b/src/Ilovepdf.php @@ -11,6 +11,7 @@ use Ilovepdf\Http\Client; use Ilovepdf\Http\ClientException; use Firebase\JWT\JWT; +use Psr\Http\Message\ResponseInterface; /** * Class Ilovepdf @@ -194,13 +195,13 @@ public static function getTokenAlgorithm() * @param array $params * @param bool $start * - * @return mixed response from server + * @return ResponseInterface response from server * * @throws AuthException * @throws ProcessException * @throws UploadException */ - public function sendRequest(string $method, string $endpoint, array $params = [], bool $start = false) + public function sendRequest(string $method, string $endpoint, array $params = [], bool $start = false): ResponseInterface { $to_server = self::getStartServer(); if (!$start && !is_null($this->getWorkerServer())) { diff --git a/src/Task.php b/src/Task.php index 84b67eb..d63c142 100644 --- a/src/Task.php +++ b/src/Task.php @@ -524,10 +524,12 @@ private function downloadRequestData(string $task): ResponseInterface $response = parent::sendRequest('get', 'download/' . $task, $body); $responseHeaders = $response->getHeaders(); - if (preg_match("/filename\*\=utf-8\'\'([\W\w]+)/", $responseHeaders['Content-Disposition'][0], $matchesUtf)) { + $contentDisposition = isset($responseHeaders['Content-Disposition']) ? $responseHeaders['Content-Disposition'] : $responseHeaders['content-disposition']; + + if (preg_match("/filename\*\=utf-8\'\'([\W\w]+)/", $contentDisposition[0], $matchesUtf)) { $filename = urldecode(str_replace('"', '', $matchesUtf[1])); } else { - preg_match('/ .*filename=\"([\W\w]+)\"/', $responseHeaders['Content-Disposition'][0], $matches); + preg_match('/ .*filename=\"([\W\w]+)\"/', $contentDisposition[0], $matches); $filename = str_replace('"', '', $matches[1]); }