request = $request = \Config\Services::request(); } public function index() { $envID = getenv('ENV_ID'); } public function endPointList(){ $endpoints = [ 'getmedia' => ['POST'], ]; return $endpoints; } public function apigate(){ $call_backend = false; $uriSegments = explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); $segLen = count($uriSegments); if ( $segLen < 4 ){ return; } $sessionId = $uriSegments[$segLen-3]; $fileSection = $uriSegments[$segLen-2]; $fileUID = $uriSegments[$segLen-1]; $supportedSections = ['profile','myfile','contracts','family']; if (!in_array($fileSection, $supportedSections)) { // section not supported return; } /* * VERIFY ALL PARAMETERS ARE GOOD */ //We can check cache for the file or // OR // WE need to ask backend for this file now / $call_backend = true; $data = [ 'action' => WRENCHBOARD_GET_MEDIA, 'sessionid' => $sessionId, 'file_section' => $fileSection, 'file_uid' => $fileUID, ]; if ($data["action"] !=''){ $wrenchboard = new \App\Models\BackendModel(); $ret = $wrenchboard->wrenchboard_api($data, $out); $out['internal_return'] = $ret; } print_r($out); $file = 'books.png'; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($file).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); readfile($file); exit; } } }