/**
  * Before saving image create album folder if does not exists.
  */
 public function beforeSave()
 {
     $path = Yii::getPathOfAlias('webroot') . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . $this->folder_uploads;
     if (!is_dir($path)) {
         mkdir($path, 0777, true);
     }
     return parent::beforeSave();
 }
Example #2
0
 public function beforeSave()
 {
     if ($this->isNewRecord && !$this->image) {
         return false;
     }
     if ($this->isNewRecord) {
         $this->realName = $this->generateUniqueName();
         $this->name = $this->realName;
         $this->fullPath = $this->getFullPath();
         $this->image->saveAs($this->getFullPath());
         $this->mimeType = $this->image->getType();
     }
     return parent::beforeSave();
 }
 public function beforeSave()
 {
     try {
         if ($this->recordId) {
             $this->deleteAllByAttributes(array('recordId' => $this->recordId, 'recordType' => self::RECORD_TYPE));
             $this->wipeFolder();
         }
         $this->checkFolder();
         $this->name = $this->realName = $this->file->getName();
         $this->mimeType = $this->file->getType();
         $this->fullPath = $this->getFolderPath() . '/' . $this->name;
         $this->file->saveAs($this->fullPath);
     } catch (Exception $e) {
         $this->addError('id', $e->getMessage());
         return false;
     }
     return parent::beforeSave();
 }