<?php

namespace App\Controllers;

class Media extends BaseController
{
    public function index(): void
    {


        $target_file = "/var/www/html/SITEFILES/TEST/test.jpg";
        $filename = $target_file;
        $file_extension = strtolower(substr(strrchr($filename,"."),1));
        $ctype="image/jpeg";
        switch( $file_extension ) {
            case "gif": $ctype="image/gif"; break;
            case "png": $ctype="image/png"; break;
            case "jpeg":
            case "jpg": $ctype="image/jpeg"; break;
            case "svg": $ctype="image/svg+xml"; break;
            case "mp4": $ctype="application/octet-stream"; break;
            // case "mp4": $ctype="video/mp4"; break;
            default:
        }

        $selectedFile  = $target_file;
        header('Content-type: ' . $ctype);
        readfile($selectedFile);
        exit();


/*
        if (file_exists($selectedFile)) {
            log_message('critical', "FILE **************************   --->0002");
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename="'.basename($selectedFile).'"');
            header('Expires: 0');
            header('Cache-Control: must-revalidate');
            header('Pragma: public');
            header('Content-Length: ' . filesize($selectedFile));
            readfile($selectedFile);
            exit;
        }
*/

       // echo $target_file;

       // return $target_file;

    }
}
