Skip to content

Commit

Permalink
fix bug in getPdf | file is no longer saved
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Appelmann committed Jul 24, 2024
1 parent a90d232 commit 1a42ff9
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/Api/Utils/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,18 @@ protected function getNextSequence(string $objectType = self::INVOICE) : SevSequ
protected function getPdf(string $path)
{
$response = $this->_get($path);
$file = $response['filename'];
file_put_contents($file, base64_decode($response['content']));

if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit();
}
$content = base64_decode($response['content']);
$filename = $response['filename'];

header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . strlen($content));

echo $content;
exit();
}
}

0 comments on commit 1a42ff9

Please sign in to comment.