diff --git a/app/Helpers/StorageHelper.php b/app/Helpers/StorageHelper.php index 6ca1216784..a56aa015b4 100644 --- a/app/Helpers/StorageHelper.php +++ b/app/Helpers/StorageHelper.php @@ -27,6 +27,35 @@ class StorageHelper } } + public static function getMediaType($file_with_path) { + + // The file exists and is allowed to be displayed inline + if (Storage::exists($file_with_path)) { + $fileinfo = pathinfo($file_with_path); + $extension = strtolower($fileinfo['extension']); + switch ($extension) { + case 'jpg': + case 'png': + case 'gif': + case 'svg': + case 'webp': + return 'image'; + case 'pdf': + return 'pdf'; + case 'mp3': + case 'wav': + case 'ogg': + return 'audio'; + case 'mp4': + case 'webm': + case 'mov': + return 'video'; + default: + return $extension; // Default for unknown types + } + } + return null; + } /** * This determines the file types that should be allowed inline and checks their fileinfo extension @@ -52,7 +81,6 @@ class StorageHelper 'pdf', 'png', 'svg', - 'svg', 'wav', 'webm', 'webp',