Symfony file upload - "Array" stored in database instead of the actual filename

Posted by Guillaume Flandre on Stack Overflow See other posts from Stack Overflow or by Guillaume Flandre
Published on 2010-04-29T13:59:25Z Indexed on 2010/04/29 16:37 UTC
Read the original article Hit count: 397

I'm using Symfony 1.4.4 and Doctrine and I need to upload an image on the server.

I've done that hundreds of times without any problem but this time something weird happens : instead of the filename being stored in the database, I find the string "Array".

Here's what I'm doing:

In my Form:

$this->useFields(array('filename'));
$this->embedI18n(sfConfig::get('app_cultures'));

$this->widgetSchema['filename'] = new sfWidgetFormInputFileEditable(array(
      'file_src'  => '/uploads/flash/'.$this->getObject()->getFilename(),
      'is_image'  => true,
      'edit_mode' => !$this->isNew(),
      'template'  => '<div id="">%file%</div><div id=""><h3 class="">change picture</h3>%input%</div>',
    ));

    $this->setValidator['filename'] = new sfValidatorFile(array(
      'mime_types' => 'web_images',
      'path' => sfConfig::get('sf_upload_dir').'/flash',
    ));

In my action:

public function executeIndex( sfWebRequest $request )
    {
        $this->flashContents = $this->page->getFlashContents();

        $flash = new FlashContent();
        $this->flashForm = new FlashContentForm($flash);

        $this->processFlashContentForm($request, $this->flashForm);

    }

protected function processFlashContentForm($request, $form)
    {
      if ( $form->isSubmitted( $request ) ) {
     $form->bind( $request->getParameter( $form->getName() ), $request->getFiles( $form->getName() ) );
     if ( $form->isValid() ) {
  $form->save();
  $this->getUser()->setFlash( 'notice', $form->isNew() ? 'Added.' : 'Updated.' );
  $this->redirect( '@home' );
     }
 }
    }

Before binding my parameters, everything's fine, $request->getFiles($form->getName()) returns my files. But afterwards, $form->getValue('filename') returns the string "Array".

Did it happen to any of you guys or do you see anything wrong with my code?

Edit: I added the fact that I'm embedding another form, which may be the problem (see Form code above).

© Stack Overflow or respective owner

Related posts about symfony

Related posts about doctrine