This article describes the implementation of Zend Framework upload file renaming. Share to everyone for your reference, specific as follows:
1. Zend Framework File Upload Rename
Class $fName = $this->_request->getpost (' FName ') on the instantiated file;
$adapter = new Zend_file_transfer_adapter_http ();
The folder where the uploaded files are stored $adapter->setdestination ('/opt/lampp/htdocs/blog/upload '); Upload configuration $adapter->addvalidator (' Extension ', false, $configs [' Extension '])/File Format Restrictions->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 [' Maxcoun T '])//Upload file number//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));
Returns the upload appears after the information if (! $adapter->receive ()) {$messages = $adapter->getmessages ()//check//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 name 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;
}
More interested in Zend related content readers can view the site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on the Zend Framework.