0

How can I make sure that the supplied file - font(TrueType)? File path may be specified with custom extension(non .ttf).

I'm confused.

BenMorel
  • 31,815
  • 47
  • 169
  • 296
Roman Nazarkin
  • 2,029
  • 4
  • 22
  • 43

1 Answers1

2

Check this: finfo

For example:

$fileName = 'file.ext';
$mimeTypes = array('font/ttf','font/truetype');
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $fileName);
if(in_array($mime, $mimeTypes)){
    echo 'font file';
}
finfo_close($finfo);

You must check FILEINFO_MIME_TYPE.

mkjasinski
  • 3,057
  • 2
  • 21
  • 21