I think the better way to do this is by saving the file always on a
temp folder (could be the /web/uploads itself) and moving it to it's
final location on the Model::save() so the model can keep track of the
file's final location.

If you really want to manage this process on the Form class, you could
use a post-validator.

On Feb 9, 1:12 pm, Manu <[email protected]> wrote:
> I have a form used to upload images in my blog engine. The files are
> uploaded to web/uploads, but I'd like to add a "choice" widget to let
> the users pick from a list of folders, for instance 'photos',
> 'cliparts', 'logos'.
>
> Here's my form
> class ImageForm extends BaseForm
> {
>   public function configure()
>   {
>     $this->widgetSchema->setNameFormat('image[%s]');
>
>     $this->setWidget('file', new sfWidgetFormInputFileEditable(
>       array(
>         'edit_mode'=>false,
>         'with_delete' => false,
>         'file_src' => '',
>         )
>     ));
>
>     $this->setValidator('file', new mysfValidatorFile(
>       array(
>         'max_size' => 500000,
>         'mime_types' => 'web_images',
>         'path' => 'uploads',
>         'required' => true
>         )
>
>     ));
>
>     $this->setWidget('folder', new sfWidgetFormChoice(array(
>       'expanded' => false,
>       'multiple' => false,
>       'choices'  => array('photos', 'cliparts', 'logos')
>        )
>     ));
>
>     $this->setValidator('folder', new sfValidatorChoice(array(
>       'choices' => array(0,1,2)
>     )));
>
>   }
>
> }
>
> and here is my action :
>   public function executeAjout(sfWebRequest $request)
>   {
>     $this->form = new ImageForm();
>
>     if ($request->isMethod('post'))
>     {
>       $this->form->bind(
>         $request->getParameter($this->form->getName()),
>         $request->getFiles($this->form->getName())
>       );
>
>       if ($this->form->isValid())
>       {
>            $this->form->getValue('file')->save();
>            $this->image = $this->form->getValue('file');
>       }
>
>     }
>
> So how do I tell the file upload widget to save the image in a
> different folder ?

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to