public function upload() { // the file property can be empty if the field is not required if (null === $this->getFile()) { return; } // use the original file name here but you should // sanitize it at least to avoid any security issues // move takes the target directory and then the // target filename to move to $this->getFile()->move($this->getUploadRootDir(), $this->getTempImgPath()); $fileContent = \file_get_contents($this->getTempImgPath()); $image = new Image(); $image->setTitle($this->getTitle())->setImage(\base64_encode($fileContent)); $this->setImage($image); unlink($this->getTempImgPath()); }
/** * @return array */ public function getPageImages() { $result = array(); $result[self::IMG_BACK] = array('isSet' => !is_null($this->backImg), 'id' => !is_null($this->backImg) ? $this->backImg->getId() : null, 'title' => !is_null($this->backImg) ? $this->backImg->getTitle() : null, 'data' => !is_null($this->backImg) ? $this->backImg->getImage() : null); $result[self::IMG_BACK_HOVER] = array('isSet' => !is_null($this->backImgHover), 'id' => !is_null($this->backImgHover) ? $this->backImgHover->getId() : null, 'title' => !is_null($this->backImgHover) ? $this->backImgHover->getTitle() : null, 'data' => !is_null($this->backImgHover) ? $this->backImgHover->getImage() : null); $result[self::IMG_BUTTON] = array('isSet' => !is_null($this->buttonImg), 'id' => !is_null($this->buttonImg) ? $this->buttonImg->getId() : null, 'title' => !is_null($this->buttonImg) ? $this->buttonImg->getTitle() : null, 'data' => !is_null($this->buttonImg) ? $this->buttonImg->getImage() : null); $result[self::IMG_BUTTON_HOVER] = array('isSet' => !is_null($this->buttonImgHover), 'id' => !is_null($this->buttonImgHover) ? $this->buttonImgHover->getId() : null, 'title' => !is_null($this->buttonImgHover) ? $this->buttonImgHover->getTitle() : null, 'data' => !is_null($this->buttonImgHover) ? $this->buttonImgHover->getImage() : null); $result[self::IMG_CONTENT] = array('isSet' => !is_null($this->content), 'id' => !is_null($this->content) ? $this->content->getId() : null, 'title' => !is_null($this->content) ? $this->content->getTitle() : null, 'data' => !is_null($this->content) ? $this->content->getImage() : null); $result[self::IMG_DESCRIPTION] = array('isSet' => !is_null($this->descriptionImg), 'id' => !is_null($this->descriptionImg) ? $this->descriptionImg->getId() : null, 'title' => !is_null($this->descriptionImg) ? $this->descriptionImg->getTitle() : null, 'data' => !is_null($this->descriptionImg) ? $this->descriptionImg->getImage() : null); $result[self::IMG_TITLE] = array('isSet' => !is_null($this->titleImg), 'id' => !is_null($this->titleImg) ? $this->titleImg->getId() : null, 'title' => !is_null($this->titleImg) ? $this->titleImg->getTitle() : null, 'data' => !is_null($this->titleImg) ? $this->titleImg->getImage() : null); return $result; }