Hi,
In your action that receive your form :
$form = new Your_Form();
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
// Uploading File
if ($form->g_nuotrauka->receive()) {
$locationFile = $form->g_nuotrauka->getFileName();
$currentMicroTime = Internim_Date::getMicrotime();
$nameFile = $currentMicroTime.'.jpg';
$fullPathNameFile = '/images/'.$nameFile;
// Renommage du fichier
$filterRename = new Zend_Filter_File_Rename(array('target'
=> $fullPathNameFile, 'overwrite' => true));
$filterRename->filter($locationFile);
}
}
The getMicroTime method :
class Internim_Date
{ public static function getMicrotime()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
}
Hope it helps,
Cheers,
Guillaume BABIK
INTERNIM
45, rue Aristide Briand
92300 LEVALLOIS
Tel : 01.40.87.11.20
Fax : 01.47.57.38.87
Mobile : 06.80.21.90.29
http://www.internim.com
-----Message d'origine-----
De : Mantasgl [mailto:[email protected]]
Envoyé : mercredi 25 février 2009 15:14
À : [email protected]
Objet : [fw-general] How to rename the uploaded file
hi,
I'm trying to rename the uploaded file, but nothing works for me. Do i need
to rename the file before or after upload?. I try to change the name to
"time().jpg", to keep file names unique. After that I want to store file
name in the mysql DB.
I'm using zf 1.7.4
My source:
$element = new Zend_Form_Element_File('g_nuotrauka');
$element->setLabel('Nuotrauka:')
->setDestination(APPLICATION_PATH.'\images')
->addValidator('Count', false, 1)
->addValidator('Size', false, 204800)
->addValidator('Extension', false, 'jpg,png,gif')
->setDecorators($this->_standardElementDecorator);
$this->addElement($element, 'g_nuotrauka');
I tried to use addFilter('Rename') in file element and in my controller, but
nothing worked out.
What i'm dooing wrong?
--
View this message in context:
http://www.nabble.com/How-to-rename-the-uploaded-file-tp22203609p22203609.ht
ml
Sent from the Zend Framework mailing list archive at Nabble.com.