Why is $file empty in custom symfony file validator?

Posted by codecowboy on Stack Overflow See other posts from Stack Overflow or by codecowboy
Published on 2010-12-21T17:00:55Z Indexed on 2010/12/21 19:54 UTC
Read the original article Hit count: 192

Filed under:
|
|

I am setting a custom file validator for a file input field in Symfony 1.4 (Doctrine)

$this->setValidator('filename', new sfValidatorFile(array(

'mime_types' => 'web_images', 'path' => sfConfig::get('sf_upload_dir').'/animals', 'validated_file_class' => 'CustomValidatedFile', 'required' =>false )));

I then want to override the save method to generate some thumbnails:

class CustomValidatedFile extends sfValidatedFile {

private $savedFilename;

// Override sfValidatedFile's save method
  public function save($file = null, $fileMode = 0666, $create = true, $dirMode = 0777) {

$this->savedFilename = $this->generateFilename(); // This makes sure we use only one savedFilename (it will be the first) if ($this->savedFilename === null ) {

$this->savedFilename = $file; }

$thumbnail = new sfThumbnail(150,150); $thumbnail->loadFile($this->getTempName()); $thumbnail->save(sfConfig::get('sf_upload_dir').'/thumbnails/thumb_'.$this->savedFilename); // Let the original save method do its magic :)

return parent::save($this->savedFilename, $fileMode, $create, $dirMode);
}
}

This fails with the error "The file "" is not readable." This is coming from sfThumbnailPlugin because the value of $file is null.

My question is why is $file null?

© Stack Overflow or respective owner

Related posts about php

Related posts about symfony