Files
WrenchBoradWeb/www-api/app/Controllers/WrenchMedia.php
T
CHIEFSOFT\ameye 28cebaa508 File read
2023-08-10 20:25:23 -04:00

91 lines
2.3 KiB
PHP

<?php
namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
class WrenchMedia extends BaseController
{
protected $db;
public $con_name = 'wrench_blog';
use ResponseTrait;
protected $request;
public function __construct()
{
$this->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;
}
}
}