I have a form that contains and form of which code goes like this for image
$image->setDestination(APPLICATION_PATH . '/../public/images/upload');
and in my controller i have
if($countryForm->image->isUploaded())
{
$countryForm->image->receive();
$countryModel->addCountry(
$countryForm->getValue('name'),
$countryForm->getValue('description'),
$this->view->baseUrl('/images/upload/'.basename($countryForm->image->getFileName()))
);
}
how can i change the name of the filename uploaded. I want to set it to
random(100).time().ext
trying this code
if($form->image->isUploaded()){
$upload = new Zend_File_Transfer();
$upload->addFilter('Rename', array('target' => APPLICATION_PATH.'/../images/upload/'.time().'.jpg', 'overwrite' => true));
$form->image->receive();
$filename = $form->image->getFilename();
$pageModel->addPage($form->getValue('pagetitle'),
$form->getValue('pagemetakeyword'),
$form->getValue('pagemetadescription'),
$form->getValue('pagecategory'),
$filename,
$form->getValue('pagecontent'),
$form->getValue('pagestatus')
);
}
would still give ‘backend/public/images/upload/picture.jpg’ in my database
I have in my form the following code
$image = $this->createElement('file', 'image');
$image->setLabel('Image: ');
$image->setRequired(FALSE);
$image->setDestination(APPLICATION_PATH . '/../public/images/upload/');
$image->addValidator('Count', false, 1);
$image->addValidator('Size', false, 1024000);
$image->addValidator('Extension', false, 'jpg,jpeg,png,gif');
$this->addElement($image);
and i am using Ubuntu
Use addFilter()
http://framework.zend.com/manual/1.12/en/zend.file.transfer.filters.html#zend.file.transfer.filters.usage
If you include the filename (here you can use your rand() function) and add it to the
targetarray value it will rename itFrom documentation:
Try: