Files
MermsMedia/app/Controllers/Media.php
T
2025-11-29 08:16:24 -05:00

112 lines
3.5 KiB
PHP

<?php
namespace App\Controllers;
use JetBrains\PhpStorm\NoReturn;
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();
}
#[NoReturn] public function imageGate(): void
{
$uriSegments = explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$segLen = count($uriSegments);
//var_dump($uriSegments);
$filename = $this->imageSets($uriSegments[$segLen - 1]);
$target_file = "/var/www/html/SITEFILES/TEST/" . $filename;
$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();
}
private function imageSets($selImg): string
{
$image_set = [
"test" => "test.jpg",
"about-kintcare" => "about-kintcare.png",
"about8-image" => "about8-image.png",
"about7-image" => "about7-image.png",
"about6-image1" => "about6-image1.png",
"about6-image2" => "about6-image2.png",
"about5-image3" => "about5-image3.png",
"about5-image2" => "about5-image2.png",
"about4-image3" => "about4-image3.png",
"about5-image1" => "about5-image1.png",
"about3-image1" => "about3-image1.png",
"about3-image2" => "about3-image2.png",
"about4-image1" => "about4-image1.png",
"about10-image" => "about10-image.png",
"about2-image1" => "about2-image1.png",
"about2-image2" => "about2-image2.png",
"about-page-sec1-image1" => "about-page-sec1-image1.png",
"about-page-sec1-image2" => "about-page-sec1-image2.png",
"about-choose-sec-image2" => "about-choose-sec-image2.png",
"about-choose-sec-image3" => "about-choose-sec-image3.png",
"about-choose-sec-image1" => "about-choose-sec-image1.png",
];
return $image_set[$selImg];
}
}