Skip to main content
Version: Fegg 5.x

Upload::mimeType

Get the MIME type a stored file is sent with

Description​

public static string Upload::mimeType( string $path, string $extension )

Returns the first type of Upload::MIME_TYPES for $extension (case does not matter). For an extension that is not in the table, returns the type finfo reads from the file $path, or application/octet-stream when it cannot be read.

Upload::upload uses it for the type of a file that is not an image (Upload::getUploadedData).

Arguments​

NameData typeDefaultRemarks
$pathstringPath of the stored file
$extensionstringExtension of the file

Example​

Controller
use Fegg\Tool\Upload;

echo Upload::mimeType($path, 'pdf'); // -> "application/pdf"
echo Upload::mimeType($path, 'XLSX'); // -> "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
echo Upload::mimeType($path, 'svg'); // -> what finfo reads, e.g. "image/svg+xml"