Rev 6749 | Rev 6858 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?phpdeclare(strict_types=1);namespace LeadersLinked\Controller;use Laminas\Db\Adapter\AdapterInterface;use LeadersLinked\Cache\CacheInterface;use Laminas\Mvc\Controller\AbstractActionController;use Laminas\Log\LoggerInterface;class StorageController extends AbstractActionController{/**** @var AdapterInterface*/private $adapter;/**** @var CacheInterface*/private $cache;/**** @var LoggerInterface*/private $logger;/**** @var array*/private $config;/**** @param AdapterInterface $adapter* @param CacheInterface $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(){// Get the file name from GET variable.$code = $this->params()->fromRoute('code', '');$fileName = $this->params()->fromRoute('filename', '');$type = $this->params()->fromRoute('type', 'user');// echo 'Code = '. $code . ' Filename = ' . $fileName . ' type = ' . $type; exit;$no_image = $this->config['leaderslinked.images_default.no_image'];$path = '';switch($type){case 'user' :$no_image = $this->config['leaderslinked.images_default.user_image'];$path = $this->config['leaderslinked.fullpath.user'];break;case 'user-profile' :$no_image = $this->config['leaderslinked.images_default.user_profile'];$path = $this->config['leaderslinked.fullpath.user'];break;case 'user-cover' :$no_image = $this->config['leaderslinked.images_default.user_cover'];$path = $this->config['leaderslinked.fullpath.user'];break;case 'company' :$no_image = $this->config['leaderslinked.images_default.company_profile'];$path = $this->config['leaderslinked.fullpath.company'];break;case 'company-cover' :$no_image = $this->config['leaderslinked.images_default.company_cover'];$path = $this->config['leaderslinked.fullpath.company'];break;case 'group' :$no_image = $this->config['leaderslinked.images_default.group_profile'];$path = $this->config['leaderslinked.fullpath.group'];break;case 'group-cover' :$no_image = $this->config['leaderslinked.images_default.group_cover'];$path = $this->config['leaderslinked.fullpath.group'];break;case 'job' :$path = $this->config['leaderslinked.fullpath.job'];break;case 'chat' :$path = $this->config['leaderslinked.fullpath.chat'];break;case 'feed' :$path = $this->config['leaderslinked.fullpath.feed'];break;case 'post' :$path = $this->config['leaderslinked.fullpath.post'];break;case 'message' :$path = $this->config['leaderslinked.fullpath.message'];break;case 'microlearning-topic' :$path = $this->config['leaderslinked.fullpath.microlearning_topic'];break;case 'microlearning-capsule' :$path = $this->config['leaderslinked.fullpath.microlearning_capsule'];break;case 'microlearning-slide' :$path = $this->config['leaderslinked.fullpath.microlearning_slide'];break;case 'daily-pulse' :$path = $this->config['leaderslinked.fullpath.daily_pulse'];break;case 'engagement-reward' :$path = $this->config['leaderslinked.fullpath.engagement_reward'] ;break;case 'knowledge-area' :$path = $this->config['leaderslinked.fullpath.knowledge_area'] ;break;default :$path = $this->config['leaderslinked.fullpath.image'];break;}if($code && $fileName) {$request_fullpath = $path . $code . DIRECTORY_SEPARATOR . $fileName;} else {$request_fullpath = $no_image;}$extensions = explode('.',$request_fullpath);$extension = strtolower(trim($extensions[count($extensions)-1]));if ($extension=='jpg' || $extension=='jpeg' || $extension=='gif' || $extension == 'png') {if(empty($fileName) || !file_exists($request_fullpath )) {$request_fullpath = $no_image;}}if(file_exists($request_fullpath)) {// Try to open fileif (!is_readable($request_fullpath)) {return $this->getResponse()->setStatusCode(500);}// Get file size in bytes.$fileSize = filesize($request_fullpath);// Get MIME type of the file.$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();}}