예제 #1
0
 public function getLogoUrl()
 {
     $attachment = Attachment::find()->where([AttachmentIndex::tableName() . '.entity' => get_class($this), AttachmentIndex::tableName() . '.entity_id' => 0, AttachmentIndex::tableName() . '.attribute' => "appLogoImage"])->leftJoin(AttachmentIndex::tableName(), AttachmentIndex::tableName() . '.attachment_id =' . Attachment::tableName() . ".attachment_id")->one();
     if ($attachment) {
         return $attachment->getUrl();
     }
     return null;
 }
예제 #2
0
 /**
  * 根据url检查该附件是否存在与数据库中,以及该附件的相关信息
  * 外部的src返回null,无效的url返回null
  * @param unknown $src
  */
 public function checkUploadImg($src)
 {
     $pathParts = pathinfo($src);
     $hash = $pathParts['filename'];
     $attachment = Attachment::find()->where(["hash" => $hash])->one();
     $file = [];
     if (!$attachment) {
         $path = \Yii::$app->get("fileStorage")->urlToPath($src);
         if (\Yii::$app->get("fileStorage")->has($path) && ($media = \Yii::$app->get("fileStorage")->get($path))) {
             $file["id"] = -1;
             $file["path"] = $path;
             $file['url'] = $src;
             $file['name'] = $hash;
             $file['hash'] = $hash;
             $file['type'] = $media->getMimetype();
             $file['size'] = $media->getSize();
             $file['extension'] = $pathParts['extension'];
             return $file;
         }
         return null;
     }
     $file = $attachment->getAttributes();
     $file['id'] = $attachment->primaryKey;
     $file['path'] = $attachment->getPath();
     $file['url'] = $attachment->getUrl();
     return $file;
 }