Пример #1
0
 /**
  * Create \Model\File instance on the basis of sent form data.
  *
  * @access   private
  * @param    array $dataBatch
  * @return   \Model\File
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 private function createFileBySentData($dataBatch)
 {
     $oLoggedUser = User::getLoggedUser();
     $aExplodedFile = explode('.', $dataBatch['name']);
     $sPath = PATH_TEMP . 'form_files' . DS . $this->getFormObject()->getName() . DS . $this->getName();
     $sPath = str_replace([PATH_PUBLIC, DS], ['', '/'], $sPath);
     $oFileManager = \FileManager::factory();
     $oFileManager->prepareDir($sPath);
     $oFileManager->parseFileData($dataBatch, $aExplodedFile[0]);
     $oFileManager->upload($sPath, FileManager::UPLOAD_SAVE_BOTH);
     $oFile = new \Model\File();
     $oFile->setPath($sPath);
     $oFile->setSize($dataBatch['size']);
     $oFile->setExt($oFileManager->getExt());
     $oFile->setName($oFileManager->getName());
     $oFile->setMime($oFileManager->getMime());
     $oFile->setStatus(0);
     if ($oLoggedUser !== NULL) {
         $oFile->setAuthor($oLoggedUser);
     }
     return $oFile;
 }
Пример #2
0
 /**
  * Create image from path
  *
  * @access	public
  * @param	string	$sPath	path to image
  * @param	integer	$sType	image type (if null, get by extension)
  * @return	\Image			Image class
  * @since	1.0.0
  * @version	1.1.9, 2014-12-14
  */
 public function __construct($sPath = FALSE, $sType = FALSE)
 {
     if ($sPath) {
         $sPath = str_replace(DIRECTORY_SEPARATOR, '/', $sPath);
         if (!file_exists($sPath)) {
             throw new \Plethora\Exception\Fatal\Image('Image with path "' . $sPath . '" does not exists!');
         }
         $this->oImageFile = \FileManager::factory()->prepareFileByPath($sPath);
         if (!$sType) {
             $this->sExtension = $this->getImageFileObject()->getExt();
             $this->sType = static::extensionToImageType($this->sExtension);
         } else {
             $this->sExtension = static::imageTypeToExtension($sType);
             $this->sType = $sType;
         }
         $this->sContentType = static::extensionToContentType($this->sExtension);
         switch ($this->sType) {
             case self::PNG:
                 $this->rImage = imagecreatefrompng($sPath);
                 break;
             case self::JPEG:
                 $this->rImage = imagecreatefromjpeg($sPath);
                 break;
             case self::GIF:
                 $this->rImage = imagecreatefromgif($sPath);
                 break;
             case self::GD:
                 $this->rImage = imagecreatefromgd($sPath);
                 break;
             case self::GD2:
                 $this->rImage = imagecreatefromgd2($sPath);
                 break;
             default:
                 throw new \Plethora\Exception\Fatal('Unknown image type!');
         }
         if (!empty($this->rImage)) {
             $this->iWidth = imagesx($this->rImage);
             $this->iHeight = imagesy($this->rImage);
         }
     }
     return $this;
 }