Skip to content

Commit

Permalink
Fixed the word generation response.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslanbaidan committed Oct 3, 2024
1 parent 3852740 commit c4cc02d
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/Controller/ApiDeliveriesModelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Monarc\BackOffice\Controller;

use Laminas\Diactoros\Response;
use Monarc\Core\Controller\AbstractController;
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
use Monarc\Core\Exception\Exception;
Expand Down Expand Up @@ -75,21 +76,22 @@ public function get($id)
$entity = $this->getService()->getEntity($id);
if (!empty($entity)) {
$lang = $this->params()->fromQuery('lang', 1);
if (isset($entity['path' . $lang]) && file_exists($entity['path' . $lang])) {
$name = pathinfo($entity['path' . $lang], PATHINFO_BASENAME);
$pathModel = getenv('APP_CONF_DIR') ?: '';
$currentPath = $pathModel . $entity['path' . $lang];
if (isset($entity['path' . $lang]) && file_exists($currentPath)) {
$filename = pathinfo($currentPath)['basename'];

$fileContents = file_get_contents($entity['path' . $lang]);
$fileContents = file_get_contents($currentPath);
if ($fileContents !== false) {
$response = $this->getResponse();
$response->setContent($fileContents);

$headers = $response->getHeaders();
$headers->clearHeaders()
->addHeaderLine('Content-Type', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')
->addHeaderLine('Content-Disposition', 'attachment; filename="' . utf8_decode($name) . '"')
->addHeaderLine('Content-Length', \strlen($fileContents));

return $this->response;
$stream = fopen('php://memory', 'rb+');
fwrite($stream, $fileContents);
rewind($stream);

return new Response($stream, 200, [
'Content-Type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'Content-Length' => strlen($fileContents),
'Content-Disposition' => 'attachment; filename="' . utf8_decode($filename) . '"',
]);
}
}
}
Expand Down

0 comments on commit c4cc02d

Please sign in to comment.