mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
namespace Shlinkio\Shlink\Common\Util;
|
|
|
|
use Zend\Diactoros\Response;
|
|
use Zend\Diactoros\Stream;
|
|
use Zend\Stdlib\ArrayUtils;
|
|
|
|
trait ResponseUtilsTrait
|
|
{
|
|
protected function generateDownloadFileResponse($filePath)
|
|
{
|
|
return $this->generateBinaryResponse($filePath, [
|
|
'Content-Disposition' => 'attachment; filename=' . basename($filePath),
|
|
'Content-Transfer-Encoding' => 'Binary',
|
|
'Content-Description' => 'File Transfer',
|
|
'Pragma' => 'public',
|
|
'Expires' => '0',
|
|
'Cache-Control' => 'must-revalidate',
|
|
]);
|
|
}
|
|
|
|
protected function generateImageResponse($imagePath)
|
|
{
|
|
return $this->generateBinaryResponse($imagePath);
|
|
}
|
|
|
|
protected function generateBinaryResponse($path, $extraHeaders = [])
|
|
{
|
|
$body = new Stream($path);
|
|
return new Response($body, 200, ArrayUtils::merge([
|
|
'Content-Type' => (new \finfo(FILEINFO_MIME))->file($path),
|
|
'Content-Length' => (string) $body->getSize(),
|
|
], $extraHeaders));
|
|
}
|
|
}
|