Here are the required modifications for to a form class that contains a file upload field in symfony 1.2 using doctrine (and it probably works with propel, too).
class NewsletterForm extends BaseNewsletterForm { public function configure() { $this->widgetSchema['file'] = new sfWidgetFormInputFileEditable(array( 'file_src' => '/uploads/'.$this->getObject()->getfile(), 'is_image' => true, 'edit_mode' => !$this->isNew(), //'template' => '<div>%file%<br />%input%<br />%delete% %delete_label%</div>', )); $this->validatorSchema['file'] = new sfValidatorFile(array( 'required' => false, 'path' => sfConfig::get('sf_upload_dir') )); $this->validatorSchema['file_delete'] = new sfValidatorPass(); } } |
If you want to override the file name generated for your uploaded file, add a ‘generateXXXFileName()’ method to your model’s class where XXX is the column name that contains the file name (in this example, our column is “file”, so the method name is ‘generateFileFilename’. It takes a single parameter, which is an instance of sfValidatedFile.
class Newsletter extends BaseNewsletter { public function generateFileFileName($file) { return $file->getOriginalName(); } } |


Hello,
I just wanna point that using the original name -as it- is not a good (storage) strategy because a filepath could then been linked to more than one item (imagine you test your form with the same image). And when you will delete the first item, the file will be physically erased while it is still referenced by the second item.
You should then consider adding a unique key to your filename, so multiple uploads -using the same file- won’t ends with the same filepath.