PHP code example of awaisjameel / mimetypes

1. Go to this page and download the library: Download awaisjameel/mimetypes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

awaisjameel / mimetypes example snippets


return [
    'mime_types_ttl' => 1440, // Default cache duration in minutes
];

use AwaisJameel\MimeTypes\MimeTypes;

//get Extension from Mime Type
try {
    $extension = MimeTypes::getExtensionOrMime('text/html');
    echo $extension; // Output: html
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

//get Mime Type from Extension
try {
    $mimeType = MimeTypesService::getExtensionOrMime('jpg');
    echo $mimeType; // Output: image/jpeg
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

//If the provided MIME type or extension is invalid, the package will throw an exception:
try {
    $result = MimeTypesService::getExtensionOrMime('invalid/mime');
} catch (Exception $e) {
    echo "Error: " . $e->getMessage(); // Output: Invalid MIME type or extension!
}
bash
php artisan vendor:publish --tag="mimetypes-config"