]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Mimetype.php
spelling: calendar
[friendica.git] / src / Util / Mimetype.php
index ea3b9e8216c80f97d21df5b0fe82ef006e7147f3..1a046e76f6d7c57ac4b062123cc0eed0c8df5474 100644 (file)
@@ -1,7 +1,24 @@
 <?php
 /**
- * @file src/Util/Mimetype.php
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
+
 namespace Friendica\Util;
 
 class Mimetype
@@ -10,12 +27,13 @@ class Mimetype
         * Return mimetype based on file extension
         *
         * @param string $filename filename
+        *
         * @return mixed array or string
         */
-       public static function contentType($filename)
+       public static function getContentType(string $filename)
        {
                $mime_types = [
-       
+
                        /*'txt' => 'text/plain',
                        'htm' => 'text/html',
                        'html' => 'text/html',
@@ -26,7 +44,7 @@ class Mimetype
                        'xml' => 'application/xml',
                        'swf' => 'application/x-shockwave-flash',
                        'flv' => 'video/x-flv',
-       
+
                        // images
                        'png' => 'image/png',
                        'jpe' => 'image/jpeg',
@@ -39,14 +57,14 @@ class Mimetype
                        'tif' => 'image/tiff',
                        'svg' => 'image/svg+xml',
                        'svgz' => 'image/svg+xml',
-       
+
                        // archives
                        'zip' => 'application/zip',
                        'rar' => 'application/x-rar-compressed',
                        'exe' => 'application/x-msdownload',
                        'msi' => 'application/x-msdownload',
                        'cab' => 'application/vnd.ms-cab-compressed',
-       
+
                        // audio/video
                        'mp3' => 'audio/mpeg',
                        'wav' => 'audio/wav',
@@ -57,14 +75,14 @@ class Mimetype
                        'avi' => 'video/x-msvideo',
                        'wmv' => 'video/x-ms-wmv',
                        'wma' => 'audio/x-ms-wma',
-       
+
                        // adobe
                        'pdf' => 'application/pdf',
                        'psd' => 'image/vnd.adobe.photoshop',
                        'ai' => 'application/postscript',
                        'eps' => 'application/postscript',
                        'ps' => 'application/postscript',
-       
+
                        // ms office
                        'doc' => 'application/msword',
                        'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
@@ -73,12 +91,12 @@ class Mimetype
                        'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
                        'ppt' => 'application/vnd.ms-powerpoint',
                        'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
-       
-       
+
+
                        // open office
                        'odt' => 'application/vnd.oasis.opendocument.text',
                        'ods' => 'application/vnd.oasis.opendocument.spreadsheet',*/
-       
+
                        // Assembled from the original Friendica list and
                        // lists from http://www.freeformatter.com/mime-types-list.html
                        // and http://www.webmaster-toolkit.com/mime-types.shtml
@@ -1070,15 +1088,14 @@ class Mimetype
                        'zoo' => 'application/octet-stream',
                        'zsh' => 'text/x-script.zsh'
                ];
-       
-               $dot = strpos($filename, '.');
+
+               $dot = strrpos($filename, '.');
                if ($dot !== false) {
                        $ext = strtolower(substr($filename, $dot + 1));
                        if (array_key_exists($ext, $mime_types)) {
                                return $mime_types[$ext];
                        }
-               } else {
-                       return 'application/octet-stream';
                }
+               return 'application/octet-stream';
        }
 }