This is my form
class Admin_Form_RoomtypeForm extends Zend_Form
{
public function init()
{
$name = new Zend_Form_Element_Text('name');
$name->setLabel('Name :');
$imagePath = '/home/dinuka/image';
$image = new Zend_Form_Element_File('image');
$image->setLabel('Image URL :');
$image->setDestination($imagePath);
$image->addValidators(array(array('IsImage', false)));
$submit = new Zend_Form_Element_Submit('submit');
$this->addElements(array($name, $image, $submit));
}
}
This is my controller
class Admin_RoomtypesController extends Zend_Controller_Action
{
public function addAction()
{
$form = new Admin_Form_RoomtypeForm();
if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
$form->populate($formData);
$name = $form->getValue('name');
}
}
}
Now i want to upload file after change file name as $name value. How can i do it?
Finally I done it as following.
-Form -
-Controller -
default image is upload to /tmp folder. We can change it using
setDestination()
method as my example.Thank for All
I had to do something like this for one of my projects, except i needed unique filenames. This isn't a perfect solution, but it may put you on the right track: