Zrobiłem ale też nie działo :/ walidator wygląda tak :
<?php
class sfFileImageValidator extends sfValidatorFile
{
/**
* Executes this validator.
*
* @param mixed A file or parameter value/array
* @param error An error message reference
*
* @return bool true, if this validator executes successfully, otherwise false
*/
protected
function configure
($options = array(), $messages = array()) {
parent::configure($options, $messages);
$this->addOption('max_width');
$this->addMessage('max_width', 'tttt');
}
public function execute(&$value, &$error)
{
if (parent::execute($value, $error))
{
// File is not a square
$is_square = $this->getParameter('is_square');
if ($is_square && $width != $height)
{
$error = $this->getParameter('is_square_error');
return false;
}
// File height too large
$max_height = $this->getParameter('max_height');
if ($max_height !== null && $max_height < $height)
{
$error = $this->getParameter('max_height_error');
return false;
}
// File width too large
$max_width = $this->getParameter('max_width');
if ($max_width !== null && $max_width < $width)
{
$error = $this->getParameter('max_width_error');
return false;
}
// File height too small
$min_height = $this->getParameter('min_height');
if ($min_height !== null && $min_height > $height)
{
$error = $this->getParameter('min_height_error');
return false;
}
// File width too small
$min_width = $this->getParameter('min_width');
if ($min_width !== null && $min_width > $width)
{
$error = $this->getParameter('min_width_error');
return false;
}
return true;
}
}
/**
* Initializes this validator.
*
* @param sfContext The current application context
* @param array An associative array of initialization parameters
*
* @return bool true, if initialization completes successfully, otherwise false
*/
public function initialize($context, $parameters = null)
{
// initialize parent
parent::initialize($context, $parameters);
// set defaults
$this->getParameterHolder()->set('max_height', null);
$this->getParameterHolder()->set('max_height_error', 'The file height is too large');
$this->getParameterHolder()->set('max_width', null);
$this->getParameterHolder()->set('max_width_error', 'The file width is too large');
$this->getParameterHolder()->set('min_height', null);
$this->getParameterHolder()->set('min_height_error', 'The file height is too small');
$this->getParameterHolder()->set('min_width', null);
$this->getParameterHolder()->set('min_width_error', 'The file width is too small');
$this->getParameterHolder()->set('is_square', false);
$this->getParameterHolder()->set('is_square_error', 'The file is not a square');
$this->getParameterHolder()->add($parameters);
return true;
}
}
?>
walidacja
<?php
$this->setValidators(array( 'photo_id' => new sfValidatorPropelChoice
(array('model' => 'Photo', 'column' => 'photo_id', 'required' => false)), 'gallery_id' => new sfValidatorChoice
(array('choices' => array_keys(Gallery
::getValuesToSelectGallery1()))), 'title' => new sfValidatorString
(array('min_length' => 1
), array('required' => 'Wpisz tytuł zdjęcia')), 'file_patch' => new sfFileImageValidator
(array('path' => sfConfig
::get('sf_upload_dir').'/gallery/temp','required' => true,'mime_types' => array('image/jpeg','image/pjpeg'),'max_size' => '261120','max_width' =>'200'), array('mime_types' =>'Nieprawidłowy format pliku','max_size'=>'Za duży rozmiar pliku. Limit to 255 Kb','required'=>'Wybierz zdjęcie') ), 'description' => new sfValidatorString
(array('required' => false)), 'tags' => new sfValidatorString
(array('required' => false)), ));
?>
Wrzucajac zdjecie na serwer w ogole nie ma walidacji szerokosci tego pliku