private function createMedia($fileName, $fullFilePath) { $filePath = str_replace(Yii::getPathOfAlias($this->module->dataAlias) . DIRECTORY_SEPARATOR, "", $fullFilePath); $md5 = md5_file($fullFilePath); $getimagesize = getimagesize($fullFilePath); $model = new P3Media(); $model->detachBehavior('Upload'); $model->default_title = $fileName; $model->original_name = $fileName; $model->type = P3Media::TYPE_FILE; $model->path = $filePath; $model->hash = $md5; $model->access_domain = '*'; if (function_exists("mime_content_type")) { $mime = mime_content_type($fullFilePath); } else { if (function_exists("finfo_open")) { $finfo = finfo_open($fullFilePath); $m = finfo_file($finfo, $filename); finfo_close($finfo); } else { $mime = $getimagesize['mime']; } } $model->mime_type = $mime; $model->info_php_json = CJSON::encode(getimagesize($fullFilePath)); $model->size = filesize($fullFilePath); if ($model->save()) { return $model; } else { $errorMessage = ""; foreach ($model->errors as $attrErrors) { $errorMessage .= implode(',', $attrErrors); } throw new CHttpException(500, $errorMessage); } }
private function createMedia($fileName, $filePath) { $fullFilePath = Yii::getPathOfAlias($this->module->dataAlias) . DIRECTORY_SEPARATOR . $filePath; $md5 = md5_file($fullFilePath); $getimagesize = getimagesize($fullFilePath); $model = new P3Media(); $model->detachBehavior('Upload'); $model->title = P3StringHelper::cleanName($fileName, 32); $model->originalName = $fileName; $model->type = 1; //P3Media::TYPE_FILE; $model->path = $filePath; $model->md5 = $md5; if (!($mime = mime_content_type($fullFilePath))) { $mime = $getimagesize['mime']; } $model->mimeType = $mime; $model->info = CJSON::encode(getimagesize($fullFilePath)); $model->size = filesize($fullFilePath); if ($model->save()) { return $model->attributes; } else { $errorMessage = ""; foreach ($model->errors as $attrErrors) { $errorMessage .= implode(',', $attrErrors); } throw new CHttpException(500, $errorMessage); } }