This article mainly introduced the implementation method of Zend Framework upload file renaming, combined with the example form analysis of the Zend Framework upload file renaming of the specific operation steps and configuration, detection, renaming operations related to the implementation skills, the need for friends can refer to the next
This paper describes the implementation method of Zend Framework upload file renaming. Share to everyone for your reference, as follows:
1. Zend Framework File Upload Rename
Instantiate the file on the special class $fname= $this->_request->getpost (' fName '); $adapter = new Zend_file_transfer_adapter_http ();// The folder $adapter->setdestination ('/opt/lampp/htdocs/blog/upload ') that holds the uploaded files;//upload Configuration $adapter->addvalidator (' Extension ', False, $configs [' Extension '])//File format limit->addvalidator (' Size ', False, Array (' min ' =>floatval ($ configs[' minsize '), ' max ' = floatval ($configs [' maxsize ']))//Set the size of the uploaded file between 1-2m->addvalidator (' Count ', false , Array (' min ' = intval ($configs [' Mincount ']), ' max ' = intval ($configs [' Maxcount ']));//number of uploaded files//rename configuration $ FileInfo = $adapter->getfileinfo ();//Get basic configuration $extname= $this->getextension ($fileInfo);//Get Extension $FILENAME=MD5 ( Time () + $fileInfo [' ffile '] [' name ']). $extName;//Rename $adapter->addfilter (' Rename ', array (' target ' = = $filename, ' overwrite ' = true));//Perform rename// Returns the upload after the message appears in the IF (! $adapter->receive ()) {$messages = $adapter->getmessages ();//detection//zend_debug::d UMP ($messages); $message = "; if (Is_array ($messages)) {foreach ($messages as $k => $v) {$message. = $k. ': '. $v. ' <br> '; }} else {$message = $messages; }}else{$this->view->message= ' upload success! ';}
2. Get the file name extension
/** * Get file extension * @param String $name file noun * @author */public function getextension ($name) { $fname = '; if ($name) { foreach ($name as $val) { $fname = $val [' name ']; } $exts = @split ("[/\\.]", $fname); $n = count ($exts)-1; $exts = $exts [$n]; return $exts; }}
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!