Rev 6749 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?php
declare(strict_types=1);
namespace LeadersLinked\Controller;
use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\Log\LoggerInterface;
class StorageNetworkController extends AbstractActionController
{
/**
*
* @var AdapterInterface
*/
private $adapter;
/**
*
* @var AbstractAdapter
*/
private $cache;
/**
*
* @var LoggerInterface
*/
private $logger;
/**
*
* @var array
*/
private $config;
/**
*
* @param AdapterInterface $adapter
* @param AbstractAdapter $cache
* @param LoggerInterface $logger
* @param array $config
*/
public function __construct($adapter, $cache , $logger, $config)
{
$this->adapter = $adapter;
$this->cache = $cache;
$this->logger = $logger;
$this->config = $config;
}
public function downloadAction()
{
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
$currentNetwork = $currentNetworkPlugin->getNetwork();
$path = $this->config['leaderslinked.fullpath.network'];
$type = $this->params()->fromRoute('type', 'logo');
if($type == 'favico') {
$filename = 'favico.png';
} else if($type == 'navbar') {
$filename = 'navbar.png';
} else {
$filename = 'logo.png';
}
$request_fullpath = $path . $currentNetwork->uuid . DIRECTORY_SEPARATOR . $filename;
if(!file_exists($request_fullpath)) {
$request_fullpath = $this->config['leaderslinked.images_default.no_image'];
}
if(file_exists($request_fullpath)) {
if (!is_readable($request_fullpath)) {
return $this->getResponse()->setStatusCode(500);
}
$fileSize = filesize($request_fullpath);
$mimeType = mime_content_type($request_fullpath);
if($mimeType===false) {
$mimeType = 'application/octet-stream';
}
$fileContent = file_get_contents($request_fullpath);
$response = $this->getResponse();
$headers = $response->getHeaders();
$headers->addHeaderLine('Content-type: ' . $mimeType);
$headers->addHeaderLine('Content-length: ' . $fileSize);
if($fileContent!==false) {
$response->setContent($fileContent);
} else {
$this->getResponse()->setStatusCode(500);
return;
}
} else {
return $this->getResponse()->setStatusCode(404);
}
return $this->getResponse();
}
}