Dynamic directory with sfValidatorFile
Say you have a form with a file upload (field image of your model for example), and that you want to save your file in a directory depending on its filename. For example, the file foobar.jpg shall be stored in fo/ob/foobar.jpg. All you have to do is implement a generateImageFilename method in your model:
public function generateImageFilename(sfValidatedFile $file)
{
$filename = $file->generateFilename();
return sprintf('%s/%s/%s', substr($filename, 0, 2), substr($filename, 1, 2), $filename);
}
And voila !
For more information on what's happening there, see sfFormDoctrine::saveFile() (around line 510 of plugins/sfDoctrinePlugin/lib/form//sfFormDoctrine.class.php)