About Zend Framework upload file Renaming implementation method

Source: Internet
Author: User
Tags zend framework
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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.