示例#1
0
 public static function moveTransformImage($srcName, $dstName, $toWidth, $toHeight, $qualityImage = 75, $typeTransform = 0)
 {
     //przeksztalca i przesuwa obrazek
     ImageTransform::copyTransformImage($srcName, $dstName, $toWidth, $toHeight, $qualityImage, $typeTransform);
     if ($srcName != $dstName) {
         @unlink($srcName);
     }
 }
 /**
  * Check dimensions, perform resize and then call parent validator.
  * 
  * @param array $value
  * @return sfValidatedFile
  */
 protected function doClean($value)
 {
     $file = parent::doClean($value);
     // resize the image by default
     if ($this->getOption('resize')) {
         // first of all, resize to given maximum and/or width but check for exception
         // if unsupported file format
         // FIXME this isn't elegant and should fail better (mime_types check should fail first before resize attempted)
         try {
             $image = new ImageTransform($file->getTempName(), $file->getType());
             $image->fit($this->getOption('max_width'), $this->getOption('max_height'));
             $image->save($file->getTempName());
         } catch (Exception $e) {
             // do nothing
         }
     } else {
         // fetch image info
         list($width, $height, $type, $attr) = getimagesize($file->getTempName());
         // do we have some exact required dimensions?
         if ($this->getOption('required_width') !== false || $this->getOption('required_height') !== false) {
             $passes_width = ($required_width = $this->getOption('required_width')) ? $width == $required_width : true;
             $passes_height = ($required_height = $this->getOption('required_height')) ? $height == $required_height : true;
             if (!$passes_height || !$passes_width) {
                 throw new sfValidatorError($this, 'required_dimensions', array('width' => $width, 'height' => $height, 'required_width' => $required_width, 'required_height' => $required_height));
             }
         }
         // check both dimensions to show useful error about both width and height if needed
         if ($width > $this->getOption('max_width') && $height > $this->getOption('max_height')) {
             throw new sfValidatorError($this, 'max_dimensions', array('width' => $width, 'height' => $height, 'max_width' => $this->getOption('max_width'), 'max_height' => $this->getOption('max_height')));
         } elseif ($width > $this->getOption('max_width')) {
             throw new sfValidatorError($this, 'max_width', array('width' => $width, 'max_width' => $this->getOption('max_width')));
         } elseif ($height > $this->getOption('max_height')) {
             throw new sfValidatorError($this, 'max_height', array('height' => $height, 'max_height' => $this->getOption('max_height')));
         }
     }
     // now tell sfValidatorFile to do its own checks
     return $file;
 }
示例#3
0
 public function addprodsubmitAction()
 {
     $oConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/wizytowki.ini', 'wizytowki');
     $oRequest = $this->getRequest();
     $oMimeValidator = new Zend_Validate_File_MimeType('image/jpg, image/jpeg');
     $oMimeValidator->setMessage('Zły format pliku.');
     $oUpload = new Zend_File_Transfer_Adapter_Http();
     $oUpload->addValidator($oMimeValidator);
     $oUpload->getValidator('Upload')->setMessage('Plik jest wymagany.', Zend_Validate_File_Upload::NO_FILE);
     $bWystapilBlad = false;
     if (!$oRequest->getParam('pro_tytul')) {
         $oRequest->setParam('error_tytul', 'Tytul jest wymagany.');
         $bWystapilBlad = $bWystapilBlad || true;
     }
     if (!$oRequest->getParam('pro_autor')) {
         $oRequest->setParam('error_autor', 'Autor jest wymagany.');
         $bWystapilBlad = $bWystapilBlad || true;
     }
     if (!$oRequest->getParam('pro_opis')) {
         $oRequest->setParam('error_opis', 'Którki opis jest wymagany.');
         $bWystapilBlad = $bWystapilBlad || true;
     }
     if (!$oRequest->getParam('pro_tekst')) {
         $oRequest->setParam('error_tekst', 'Text jest wymagany.');
         $bWystapilBlad = $bWystapilBlad || true;
     }
     if (!$oUpload->isValid('logo')) {
         $aMessages = $oUpload->getMessages();
         $oRequest->setParam('error_logo', current($aMessages));
         $bWystapilBlad = $bWystapilBlad || true;
     }
     if (!$oRequest->getParam('pro_cena')) {
         $oRequest->setParam('error_cena', 'Cena jest wymagana.');
         $bWystapilBlad = $bWystapilBlad || true;
     }
     /*if( !$oUpload->isValid( 'zdjecie' ) ) {
     
     			$aMessages = $oUpload->getMessages();
     			$oRequest->setParam( 'error_zdjecie', current($aMessages) );
     			$bWystapilBlad = $bWystapilBlad || true;
     		}*/
     if ($bWystapilBlad) {
         return $this->_forward('addprod');
     }
     $sLogoKatalog = $oConfig->produkty->logo->katalog;
     $sLogoNazwa = FileNameManager::getName($sLogoKatalog, $oUpload->getFileName('logo', false));
     $oUpload->addFilter('Rename', $sLogoKatalog . $sLogoNazwa);
     $oUpload->receive('logo');
     ImageTransform::scaleTransformImage($sLogoKatalog . $sLogoNazwa, $oConfig->produkty->logo->szerokosc, $oConfig->produkty->logo->wysokosc, 75, 1);
     $oProdukty = new Produkty();
     try {
         $aDane = array('pro_tytul' => $oRequest->getParam('pro_tytul'), 'pro_autor' => $oRequest->getParam('pro_autor'), 'pro_opis' => $oRequest->getParam('pro_opis'), 'pro_tekst' => $oRequest->getParam('pro_tekst'), 'pro_cena' => $oRequest->getParam('pro_cena'), 'pro_logo' => $sLogoNazwa);
         $iProId = $oProdukty->insert($aDane);
         $okategorie = new kategorie();
         $okategorie->dopiszDoKategorii($oRequest->getParam('kategorie'), $iProId);
         $this->_redirect('admin/produkty');
     } catch (Exception $e) {
         if ($sLogoNazwa && file_exists($sLogoKatalog . $sLogoNazwa)) {
             unlink($sLogoKatalog . $sLogoNazwa);
         }
         echo 'Wystąpił błąd w linii ' . $e->getLine() . ': ' . $e->getMessage();
     }
 }