FileUpload::getFileName PHP Method

getFileName() protected method

获取新的文件名
protected getFileName ( )
    protected function getFileName()
    {
        //生成随机名
        $name = $this->randName();
        //生成目录
        $dir = $this->makeDir();
        //生成新的文件名路径
        $filename = $dir . $name . '.' . $this->instance->extensionName;
        return $filename;
    }

Usage Example

 /**
  * Goes through the array of files and processes them accordingly.
  * The result is an array of the appropiate Resource class that has been
  * created using the ResourceFactory class.
  *
  * @return An array of Upload objects that have already been moved to a safer
  * location.
  */
 function process($destinationFolder)
 {
     // first, check if the upload feature is available
     $config =& Config::getConfig();
     if (!$config->getValue("uploads_enabled")) {
         return FILE_UPLOADS_NOT_ENABLED;
     }
     // array used to store the files that have already been saved
     $uploads = array();
     if ($destinationFolder[strlen($destinationFolder - 1)] != "/") {
         $destinationFolder .= "/";
     }
     foreach ($this->_files as $file) {
         $upload = new FileUpload($file);
         $fileName = $upload->getFileName();
         if ($this->my_move_uploaded_file($upload->getTmpName(), $destinationFolder . $fileName)) {
             $upload->setFolder($destinationFolder);
             $upload->setError(0);
         } else {
             $upload->setError(1);
         }
         array_push($uploads, $upload);
     }
     return $uploads;
 }
All Usage Examples Of FileUpload::getFileName