Get request media type, if known.

Note: This method is not part of the PSR-7 standard.

@return string|null The request media type, minus content-type params
352370
public function getMediaType()
    {
        $contentType = $this->getContentType();
        if (is_string($contentType)) {
            $contentTypeParts = preg_split('/\s*[;,]\s*/', $contentType);

            return isset($contentTypeParts[0]) ? strtolower($contentTypeParts[0]) : null;
        }

        return null;
    }
142748
public function getPhpType()
    {
        if (isset(self::$_phpTypesByProtobufType[$this->getType()])) {
            return self::$_phpTypesByProtobufType[$this->getType()];
        } else {
            return null;
        }
    }
409964
public function getPostType()
    {
        $called_class_segments = explode('\\', get_called_class());
        $class_name = end($called_class_segments);
        return (is_null($this->post_type))
            ? Str::machine(Str::camelToHuman($class_name), Base::SEPARATOR)
            : $this->post_type;
    }
595316
public function getOutputType()
    {
        $type = $this->outputType;

        if (is_null($type)) {
            $type = $this->getInfo('type');
        }

        return preg_replace('~image/~', null, $this->formatType($type));
    }
1215804
public function getMimeType()
    {
        if ($this->exists()) {
            $finfo = new \finfo(FILEINFO_MIME_TYPE | FILEINFO_PRESERVE_ATIME);
            $mime = $finfo->file($this->getRealPath());
            return $mime;
        }
        return null;
    }
408886
public function getMediaPlayerAttribute()
    {
        if (!in_array($this->attributes['type'], ['video', 'audio'])) {
            return null;
        }

        return html_raw(view('shortcodes.media_player', [
            'media' => (object) $this->toArray()
        ]));
    }
882850
public function getMediaType()
    {
        if ($this->mediaType === null) {
            return Utility\MediaTypes::getMediaTypeFromFilename($this->filename);
        } else {
            return $this->mediaType;
        }
    }
896654
private function getTemplateParameters(Request $request)
    {
        // When the media bundle is available, we show a link in the header to the media chooser
        $allBundles = $this->getParameter('kernel.bundles');
        $mediaChooserLink = null;

        if (array_key_exists('KunstmaanMediaBundle', $allBundles)) {
            $params = ['linkChooser' => 1];
            $cKEditorFuncNum = $request->get('CKEditorFuncNum');
            if (!empty($cKEditorFuncNum)) {
                $params['CKEditorFuncNum'] = $cKEditorFuncNum;
            }
            $mediaChooserLink = $this->generateUrl(
                'KunstmaanMediaBundle_chooser',
                $params
            );
        }

        return [
            'mediaChooserLink' => $mediaChooserLink,
        ];
    }
445944
public function getMediaType($mimetype)
    {
        foreach ($this->mediaTypes as $type => $mimeTypes)
        {
            if (in_array($mimetype, $mimeTypes))
            {
                return $type;
            }
        }

        return null;
    }
516042
private String getRequestHeaderContentType() {
        String contentType = getRequestHeaderValue("Content-Type");
        if (contentType != null) {
            // remove parameter (Content-Type := type "/" subtype *[";" parameter] )
            int index = contentType.indexOf(';');
            if (index > 0)
                contentType = contentType.substring(0, index);
            contentType = contentType.trim();
        }
        return contentType;
    }
1076105
public function getMediaType($revision = null)
	{
		// Without revision, use current info
		if (!isset($revision)) {
			return $this->info['mediatype'];
		}

		// Obtain the properties of the revision
		if (($info = $this->getRevision($revision)) === null) {
			return null;
		}

		return $info['mediatype'];
	}
1000761
public function index(Request $request, $type = 'default')
    {
        // Get the configuration
        $config = Config::get('media-upload');

        $configType = Config::get('media-upload.types.'.$type);

        if ( ! $configType )
        {
            return [ 'error' => 'type-not-found' ];
        }

        // Check if file is uploaded
        if ( ! \Input::hasFile('file') )
        {
            return [ 'error' => 'file-not-found' ];
        }

        $file  = \Input::file('file');

        // get file size in Bytes
        $file_size = $file->getSize();

        // Check the file size
        if ( $file_size > $config['max_size'] * 1024 || ( isset($configType['max_size']) && $file_size > $configType['max_size'] * 1024 ) )
        {
            return [ 'error' => 'limit-size' ];
        }

        // get the extension
        $ext = strtolower( $file->getClientOriginalExtension() );

        // checking file format
        $format = $this->getFileFormat($ext);

        // TODO: check file format
        if( isset($configType['format']) && ! in_array($format, explode('|', $configType['format'])) )
        {
            return [ 'error' => 'invalid-format' ];
        }

        // saving file
        $filename = date('U').str_random(10);
        $file->move(public_path().'/'.$config['dir'].'/'.$type, $filename.'.'.$ext);

        $file_path = $config['dir'].'/'.$type.'/'.$filename.'.'.$ext;

        if ( $format == 'image' && isset($config['types'][$type]['image']) && count($config['types'][$type]['image']) )
        {

            $img = Image::make(public_path().'/'.$file_path);

            foreach($config['types'][$type]['image'] as $task => $params)
            {
                switch($task) {
                    case 'resize':
                        $img->resize($params[0], $params[1]);
                        break;
                    case 'fit':
                        $img->fit($params[0], $params[1]);
                        break;
                    case 'crop':
                        $img->crop($params[0], $params[1]);
                        break;
                    case 'thumbs':
                        $img->save();

                        foreach($params as $name => $sizes) {
                            
                            $img->backup();

                            $thumb_path = $config['dir'].'/'.$filename.'-'.$name.'.'.$ext;

                            $img->fit($sizes[0], $sizes[1])->save($thumb_path);

                            $img->reset();
                        }
                        break;
                }
            }

            $img->save();
        }

        return [
            'original' => [
                'name' => $file->getClientOriginalName(),
                'size' => $file_size,
            ],
            'ext' => $ext,
            'format' => $format,
            // 'image' => [
            //     'size' =>$img->getSize(),
            // ],
            'name' => $filename,
            'path' => $file_path,
        ];

    }
731497
public function getClientMediaType() : string
    {
        return ($this->clientFilename === null) ? $this->fileStream->getMimeType() : $this->retrieveFileMimeType($this->clientFilename);
    }
757880
public String getContentType() {
        final Object contentType = getHeader(HttpMessageHeaders.HTTP_CONTENT_TYPE);

        if (contentType != null) {
            return contentType.toString();
        }

        return null;
    }
31848
public function getType()
    {
        $mimeType = preg_replace('#^([^/]+)/.*$#', '$1', $this->getMimeType());

        if ($mimeType == 'video') {
            return Media::VIDEO;
        }

        if ($mimeType == 'audio') {
            return Media::AUDIO;
        }

        if ($mimeType == 'image') {
            return Media::IMAGE;
        }

        $extension = $this->getExtension();

        if (in_array($extension, $this->imagesExtensions())) {
            return Media::IMAGE;
        }

        if (in_array($extension, $this->audiosExtensions())) {
            return Media::AUDIO;
        }

        if (in_array($extension, $this->videosExtensions())) {
            return Media::VIDEO;
        }

        return Media::OTHER;
    }
496771
protected function getContenType(): string
	{
		return $this->contentType ?? ($this->fileSystem->info($this->filePath)->getMimeType() ?? 'application/octet-stream');
	}
287728
public function getMediaUri()
    {
       $folder = $this->getMediaFolder();

       if (strpos($folder, '://')) {
           return $folder;
       }

       /** @var UniformResourceLocator $locator */
       $locator = Grav::instance()['locator'];
       $user = $locator->findResource('user://');
       if (strpos($folder, $user) === 0) {
           return 'user://' . substr($folder, \strlen($user)+1);
       }

       return null;
    }