Newscoop\Storage::getMimeType PHP Метод

getMimeType() публичный Метод

Get mime type
public getMimeType ( string $key ) : string
$key string
Результат string
    public function getMimeType($key)
    {
        $realpath = realpath("{$this->root}/{$key}");
        $finfo = new \finfo(FILEINFO_MIME);
        return $finfo->file($realpath);
    }

Usage Example

Пример #1
0
 /**
  * Replace item
  *
  * @param string $key
  * @param Zend_Form_Element_File $file
  * @return void
  * @throws InvalidArgumentException
  */
 public function replaceItem($key, \Zend_Form_Element_File $file)
 {
     $oldMime = current(explode(';', $this->storage->getMimeType($key)));
     $newMime = current(explode(';', $file->getMimeType()));
     if ($oldMime != $newMime && !(in_array($oldMime, self::$equivalentMimeTypes) && in_array($newMime, self::$equivalentMimeTypes))) {
         throw new \InvalidArgumentException(sprintf('You can only replace a file with a file of the same type.  The original file is of type "%s", and the file you uploaded was of type "%s".', $oldMime, $newMime));
     }
     $this->storage->storeItem($key, file_get_contents($file->getFileName()));
 }