本文整理汇总了PHP中yii\helpers\BaseFileHelper::getMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseFileHelper::getMimeType方法的具体用法?PHP BaseFileHelper::getMimeType怎么用?PHP BaseFileHelper::getMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\BaseFileHelper
的用法示例。
在下文中一共展示了BaseFileHelper::getMimeType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionUpload
/**
* upload new media files and link to a given content category id
* @menuLabel __HIDDEN__
* @return string
*/
public function actionUpload($targetCategoryId, $mediaType = null)
{
if ($mediaType != null && MediaController::$MEDIA_TYPE_AUDIO != $mediaType && MediaController::$MEDIA_TYPE_IMAGE != $mediaType && MediaController::$MEDIA_TYPE_VIDEO != $mediaType) {
throw new InvalidParamException('The media type ' . $mediaType . ' is not known.');
}
$model = new MediaBrowserImageUpload();
$targetCategoryId = intval($targetCategoryId);
$model->targetCategoryId = $targetCategoryId;
$msg = "";
if (Yii::$app->request->isPost) {
$model->file = UploadedFile::getInstances($model, 'file');
//check if folder exists
$cagtegory = CmsContentCategory::findOne($targetCategoryId);
if ($cagtegory == null) {
throw new InvalidValueException('the given catgeory id is not valid. Upload failed');
}
if ($model->file && $model->validate()) {
foreach ($model->file as $file) {
/* @VAR $file UploadedFile */
$targetPath = $this->getFullUploadPathForFile($file);
if ($file->saveAs($targetPath)) {
$pathInfo = pathinfo($targetPath);
$content = new CmsContentMedia();
$content->init();
$content->mime_type = BaseFileHelper::getMimeType($targetPath);
$content->file_name = $pathInfo['basename'];
$content->file_path = $pathInfo['dirname'];
$content->filesize_bytes = $file->size;
$content->content_category_id = $targetCategoryId;
$content->media_type = $this->module->getMediaTypeForMimeType($content->mime_type);
if ($content->media_type == MediaController::$MEDIA_TYPE_IMAGE) {
$dimensions = $this->getImageDimensions($targetPath);
if ($dimensions != null) {
$content->dimension_width = $dimensions['width'];
$content->dimension_height = $dimensions['height'];
} else {
$msg .= 'Unable to detect image dimensions for image ' . $content->file_name;
}
}
$content->created_datetime = new Expression('NOW()');
$content->createdby_userid = Yii::$app->user->id;
if (!$content->insert(true)) {
$this->layout = 'modalLayout';
return $this->render('fileUpload', ['model' => $model, 'errors' => $content->errors, 'mediaType' => $mediaType, 'msg' => $msg]);
//throw new Exception('The upload of one or more files failed. Most likely validation of properties failed');
}
} else {
throw new \Exception('The upload of one or more files failed.');
}
}
//reload browser for current folder
return $this->redirect(Url::toRoute(['media/mediabrowser', 'mediatype' => $mediaType, 'activeCategoryId' => $targetCategoryId]));
}
}
$this->layout = 'modalLayout';
return $this->render('fileUpload', ['model' => $model, 'mediaType' => $mediaType, 'msg' => $msg]);
}