The save() methods reads its location the same way you can by using
sfConfig::get('sf_upload_dir'). And where there's a getter theres
usually a setter. So before calling save use:
sfConfig::set('sf_upload_dir',
sfConfig::get('sf_root_dir').DIRECTORY_SEPERATOR.'new_directory');
Now when save calls sfConfig::get() for the upload directory it will use
your setting.
\On 09/02/2011 17:12, Manu 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 ?
--
Gareth McCumskey
http://garethmccumskey.blogspot.com
twitter: @garethmcc
identi.ca: @garethmcc
--
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 symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en