protected function importimagefromstr($media, $path, $flag) { $mediaIds = []; yii::info($media, __METHOD__); $hash = md5($media); if (($armodel = Asset::findOne(['mediahash' => $hash])) !== null) { return [$armodel->Id]; } $media_doc = ['filename' => $media, 'path' => '@media/' . $path . '/' . $media, 'uri' => $path . '/' . $media, 'description' => '', 'mimetype' => '', 'source' => '', 'embedcode' => '', 'mediahash' => $hash, 'metainfo' => '', 'createdBy' => 40, 'updatedBy' => 40, 'status' => 1]; $assetmodel = new Asset(); $assetmodel->load($media_doc, ''); $assetmodel->save(false); $mediaIds[] = $assetmodel->Id; try { $tag = Asset::loadTagmodel($flag, true); Asset::saveAssetTag($assetmodel, $tag); } catch (\yii\base\ErrorException $error) { Yii::info(print_r($error, true), __METHOD__); } return $mediaIds; }