Anyone familiar with Zend_Form and specifically Zend_Form_Element_File? I am having trouble figuring out how to rename an uploaded file? So far I have the following form…
class Image_Add_Form extends Zend_Form
{
public function init()
{
$this->setMethod('post');
$this->setAction('');
$this->setAttrib('enctype', 'multipart/form-data');
$fileDestination = realpath(APPLICATION_PATH . '/../public/images/events');
$this->addElement('file', 'image', array(
'label' => 'Upload A Picture: ',
'required' => true,
'destination' => $fileDestination,
'validators' => array(
array('Count', false, array(1)),
array('Size', false, array(1048576 * 5)),
array('Extension', false, array('jpg,png,gif')),
)
));
$this->addElement('image', 'submit', array(
'decorators' => array(array('viewHelper', array('class' => 'submit'))),
'src' => '/public/images/upload_image.png',
'required' => false,
'class' => 'submit',
'ignore' => true,
));
}
}
As far as I know the “destination” option only allows you to specify the directory that a file is uploaded to, but not a filename. And I’m not aware of any other option for the filename. I’m concerned about file name clashes and security if I just use the file name provided by the user.
In addition in the form processing script, as soon as I call $form->getValues(), the file is uploaded with the user provided file name.
Anyone know a solution to this?