public function init() { if (!$this->fileInputName) { throw new yii\base\InvalidConfigException('fileInputName属性必须设置'); } if (!file_exists(Yii::getAlias($this->savePath))) { throw new yii\base\InvalidConfigException('保存目录不存在'); } $this->_uploadFile = UploadedFile::getInstanceByName($this->fileInputName); if ($this->_uploadFile) { $this->fileMimeType = FileHelper::getMimeType($this->_uploadFile->tempName); } else { $this->error = '没有上传文件'; } }
/** * Возвращает mime тип файла * @return string */ public function getMimeType() { return FileHelper::getMimeType($this->path); }