-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCdnController.php
More file actions
23 lines (22 loc) · 850 Bytes
/
CdnController.php
File metadata and controls
23 lines (22 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
//namespace App\Controllers\CDN;
//use App\Controllers\BaseController;
class CdnController extends BaseController{
public function cdn() {
$uri_string = uri_string();
if(strlen($uri_string) > 0){
$file_path = ROOTPATH . "public/site-assets/{$uri_string}";
if (file_exists($file_path)) {
$file = new \CodeIgniter\Files\File($file_path);
$content = $file->openFile('r');
$mime_type = $file->getMimeType();
return $this->response->setContentType($mime_type)->setBody(file_get_contents($file_path));
} else {
throw new \CodeIgniter\Exceptions\PageNotFoundException('File not found: ' . esc($uri_string));
}
}else{
return $this->response->setStatusCode(400);
}
}
}
?>