开发者

symfony 1.4 process file after upload in form, doesn't sends data to DB, but it saves file in disk

I have a form with a sfWidgetFormInputFile field. I'm uploading images, and after the upload, I would like to do some processing to the file just uploaded.

I know I can use a validated_file_class for this. I'm overwritting the save() method in my custom class, and the file gets correctly saved but the storing in the database doesn't works, it just sends me null values for the filename field. Am I missing something?

Here is the relevant code:

class MyForm extends BaseMyForm
{
  public function configure()
  {
    $this->widgetSchema['image'] = new sfWidgetFormInputFile();
    $this->validatorSchema['image'] = new sfValidatorFile(array(
                                         'required' => true,
                                         'path' => sfConfig('sf_upload_dir'),
                                         'mime_types' => 'web_images',
                                         'validated_file_开发者_JAVA技巧class' => 'MyCustomValidatedFile'
                                                          ));
  }
}

class MyCustomValidatedFile extends sfValidatedFile
{
  public function save($file = null, $fileMode = 0666, $create = true, $dirMode = 0777)
  {
    parent::save($file, $fileMode, $create, $dirMode);
  }
}


Ok, I got it...

I was just missing the return statement for the save() method... It should return the name of the file just saved without path prefix.

$fn = parent::save($file, $fileMode, $create, $dirMode);
//processing
return $fn;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜