The implementation method of Zend framework uploading file renaming _php tips

Source: Internet
Author: User
Tags foreach file upload min zend zend framework

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.

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.