LLMS_Mime_Type_Extractor::from_file_path( string $file )

Retrieve the mime type from file path.


Parameters Parameters

$file

(string) (Required) The file path string.


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/class-llms-mime-type-extractor.php

	public static function from_file_path( $file ) {

		if ( ! is_readable( $file ) || is_dir( $file ) || is_link( $file ) ) {
			return self::DEFAULT_MIME_TYPE;
		}

		$mime_type   = '';
		$file_suffix = pathinfo( $file, PATHINFO_EXTENSION );
		$suffix      = strtolower( $file_suffix );

		if ( isset( self::$mime_type_list[ $suffix ] ) ) {
			$mime_type = self::$mime_type_list[ $suffix ];
		}

		if ( ! $mime_type && function_exists( 'finfo_file' ) ) {
			$finfo     = finfo_open( FILEINFO_MIME_TYPE );
			$mime_type = finfo_file( $finfo, $file );
			finfo_close( $finfo );
		}

		if ( ! $mime_type && function_exists( 'mime_content_type' ) ) {
			$mime_type = mime_content_type( $file );
		}

		return $mime_type ? $mime_type : self::DEFAULT_MIME_TYPE;
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.