Skip to content

Commit

Permalink
fix content-disposition
Browse files Browse the repository at this point in the history
  • Loading branch information
maztch committed Apr 4, 2024
1 parent 61ff8d1 commit 0bc0b96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Ilovepdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Ilovepdf\Http\Client;
use Ilovepdf\Http\ClientException;
use Firebase\JWT\JWT;
use Psr\Http\Message\ResponseInterface;

/**
* Class Ilovepdf
Expand Down Expand Up @@ -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())) {
Expand Down
6 changes: 4 additions & 2 deletions src/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down

0 comments on commit 0bc0b96

Please sign in to comment.