<?php

class PaxyprestaPaxyassetsModuleFrontController extends ModuleFrontController
{
    public function __construct()
    {
        parent::__construct();
    }

    public function initContent(){
        $file = Tools::getValue('file');

        if (!$file || strpos($file, '..') !== false) {
            throw new Exception('File is not defined correctly');
        }

        $url = __DIR__ . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, ['..', '..', 'img']) . DIRECTORY_SEPARATOR . $file;
        if (!is_file($url)) {
            throw new Exception('Such file does not exist');
        }

        $info = pathinfo($url);

        header('Content-type: image/' . $info['extension']);
        echo file_get_contents($url);
        die();
    }
}
