* Edit post
* Report this post
* Reply with quote
Upload File
Postby sami_ghname82 on Mon Mar 22, 2010 10:24 am
Hi All
I have this code to upload a file to server. I need if the file exist change
file name by code and uploaded another time not by the user.
How can proposed name to file.
if($this->validateForm()){
//Assign info from form to variable
$dateCreated = new Zend_Date(Zend_Date::now());
$this->uploadInfo['accountment_id'] = $this->_accountmentId;
$this->uploadInfo['date_modified'] = $dateCreated->get('YYYY-MM-dd H:m:s');
$this->uploadInfo['date_create'] = $dateCreated->get('YYYY-MM-dd H:m:s');
$upload = new Zend_File_Transfer_Adapter_Http();
//Prepare folder to move file
$upload->setDestination(APPLICATION_ROOT . '/statement')
//add some validation
->addValidator('NotExists', false , APPLICATION_ROOT . '/statement')
->addValidator('Extension', false, array('xls', 'xlsx' , 'pdf' , 'doc' ,
'docx'))
->addValidator('Count', false , array( 'min' => 1, 'max' => 1));
//get file name uploaded
$this->uploadInfo['dir'] = $upload->getFileName('file');
//Check is the upload file valid
if (!$upload->isValid())
{
//If not valid assign error to view
$this->view->fileError = $upload->getMessages();
}else if(!$upload->receive()){
//If can't upload this file assign error to view
$this->view->fileError = $upload->getMessages();
}else{
//if file uploaded and valid add statement
$this->addStatement();
$this->view->success = 'The statement has been uploaded successfully. ';
}
}else{
//If form not valid assign error to view
$this->view->error = $this->errorMessage;
}
sami_ghname82
Posts: 25
Joined: Tue Jan 19, 2010 10:04 am
* Private message
--
View this message in context:
http://n4.nabble.com/Upload-File-tp1677395p1677395.html
Sent from the Zend Framework mailing list archive at Nabble.com.