Files
WrenchBoradWeb/www-api/app/Controllers/WrenchMedia.php
T
CHIEFSOFT\ameye ed824316a7 banners
2023-08-11 12:13:27 -04:00

109 lines
3.0 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 $savePath = WRENCHBOARD_UPLOAD_PATH;
public function __construct()
{
$this->request = $request = \Config\Services::request();
//define('WRENCHBOARD_UPLOAD_PATH', '/opt/wrenchboard/TEST/');
$this->savePath= '/opt/wrenchboard/TEST/';
}
public function index()
{
$envID = getenv('ENV_ID');
}
public function endPointList(){
$endpoints = [
'getmedia' => ['POST'],
];
return $endpoints;
}
const WRENCH_FILE_PROFILE = 100;
const WRENCH_FILE_MYFILE = 200;
const WRENCH_FILE_CONTRACTS = 300;
const WRENCH_FILE_FAMILY = 400;
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'=>100,'myfile'=>200,'contracts'=>300,'family'=>400];
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,
'file_section_no' =>$supportedSections[$fileSection]
];
if ($data["action"] !=''){
$wrenchboard = new \App\Models\BackendModel();
$ret = $wrenchboard->wrenchboard_api($data, $out);
$out['internal_return'] = $ret;
}
//print_r($out);
// MAKE SURE FOLDER AS PER PROCESS IS AVAILABLE
$selectedFile = $this->savePath.'PROFILE/'.$out["member_uid"]."/MYFILES/". $out["saved_file_name"];
log_message('critical', "wrenchboard_api-CALL MEDIA selectedFile DATA".$selectedFile );
$file = $selectedFile; // '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;
}
}
}