CRUDlex\MimeTypes::getMimeType PHP Method

getMimeType() public method

Function to get the mimetype of a file.
public getMimeType ( string $file ) : string
$file string the file to get the mimetype from
return string the mimetype
    public function getMimeType($file)
    {
        if (file_exists($file)) {
            return $this->getMimeTypeByFileInfo($file);
        }
        return $this->getMimeTypeByExtension($file);
    }

Usage Example

Beispiel #1
0
 public function testGetMimeType()
 {
     $mimeTypes = new MimeTypes();
     $read = $mimeTypes->getMimeType('test.css');
     $expected = 'text/css';
     $this->assertSame($expected, $read);
     $read = $mimeTypes->getMimeType('test.jpg');
     $expected = 'image/jpeg';
     $this->assertSame($expected, $read);
     $read = $mimeTypes->getMimeType(__DIR__ . '/../../src/static/css/vendor/bootstrap/bootstrap.css');
     $expected = 'text/css';
     $this->assertSame($expected, $read);
     $read = $mimeTypes->getMimeType(__DIR__ . '/../../src/static/images/flags/ad.png');
     $expected = 'image/png';
     $this->assertSame($expected, $read);
     $read = $mimeTypes->getMimeType(__DIR__ . '/../../src/static/js/vendor/moment.min.js');
     $expected = 'application/x-javascript';
     $this->assertSame($expected, $read);
     $read = $mimeTypes->getMimeType(null);
     $expected = 'application/octet-stream';
     $this->assertSame($expected, $read);
     $read = $mimeTypes->getMimeType('foo');
     $expected = 'application/octet-stream';
     $this->assertSame($expected, $read);
     $read = $mimeTypes->getMimeType('');
     $expected = 'application/octet-stream';
     $this->assertSame($expected, $read);
 }
All Usage Examples Of CRUDlex\MimeTypes::getMimeType