TEXT 30
Untitled Guest on 14th March 2023 07:32:17 PM
  1. <?php
  2.  
  3. /**
  4.  * @package    phpListings
  5.  * @author     phpListings Team <info@phplistings.com>
  6.  * @copyright  2020 phpListings.com
  7.  * @license    https://www.phplistings.com/eula
  8.  */
  9.  
  10. namespace App\Controllers;
  11.  
  12. class Media
  13.     extends \App\Src\Mvc\BaseController
  14. {
  15.  
  16.     public function actionIndex($params)
  17.     {
  18.         if (isset($params['id'])) {
  19.             if (isset($params['type']) && !in_array($params['type'], ['small', 'medium', 'large'])) {
  20.                 throw new \App\Src\Http\NotFoundHttpException();
  21.             }
  22.  
  23.             $file = \App\Models\File::query()
  24.                 ->where('id', $params['id'])
  25.                 ->first();
  26.  
  27.             if (null !== $file) {
  28.             if ($file->uploadtype_id == 21 && false === auth()->check()) {
  29.             throw new \App\Src\Http\NotFoundHttpException();
  30.            
  31.             }
  32.                 $file = (isset($params['type'])) ? $file->{$params['type']}() : $file;
  33.                 if ($file->name . '.' . $file->extension == $params['name']) {
  34.                     try {
  35.                         return fileResponse($file->getPath())
  36.                             ->withEtag(md5($file->getUrl()))
  37.                             ->withHeaders([
  38.                                 'Cache-Control' => 'max-age=2592000',
  39.                             ]);
  40.                     } catch (\App\Src\Http\File\FileNotFoundException $e) {
  41.                         throw new \App\Src\Http\NotFoundHttpException();
  42.                     }
  43.                 }
  44.             }
  45.         }
  46.  
  47.         throw new \App\Src\Http\NotFoundHttpException();
  48.     }
  49.  
  50. }

Paste is for source code and general debugging text.

Raw Paste

Login or Register to edit or fork this paste. It's free.