public function handle(FileUpload $uploader, FileInfo $fileinfo)
 {
     // TODO Auto-generated method stub
     $filename = $fileinfo->getPath();
     $realpath = $uploader->getFileBaseDir() . DIRECTORY_SEPARATOR . $filename;
     //resize the file
     list($o_width, $o_height, ) = getimagesize($realpath);
     list($des_width, $des_height) = $this->getDestSize(array($o_width, $o_height));
     $destination = $this->getDestName($fileinfo, array($des_width, $des_height));
     $full_destination = $uploader->getFileBaseDir() . DIRECTORY_SEPARATOR . $destination;
     $source = imagecreatefromstring(file_get_contents($realpath));
     if (function_exists('imagescale')) {
         $dest = imagescale($source, $des_width, $des_height);
         if ($dest) {
             $result = true;
         } else {
             $result = false;
         }
     } else {
         $dest = imagecreatetruecolor($des_width, $des_height);
         $result = imagecopyresampled($dest, $source, 0, 0, 0, 0, $des_width, $des_height, $o_width, $o_height);
     }
     imagedestroy($source);
     if ($result) {
         switch (strtolower($fileinfo->getExtension())) {
             case 'jpg':
             case 'jpeg':
             default:
                 $result = imagejpeg($dest, $full_destination);
                 break;
             case 'png':
                 $result = imagepng($dest, $full_destination);
                 break;
             case 'gif':
                 $result = imagegif($dest, $full_destination);
                 break;
             case 'bmp':
                 throw new Exception('不支持bmp文件');
                 break;
         }
         imagedestroy($dest);
         if ($result) {
             $info = new FileInfo($fileinfo->getName(), filesize($full_destination), $destination, $fileinfo->getType());
             return $info;
         }
         return false;
     }
     return false;
 }
 public function upload()
 {
     $result = parent::upload();
     if ($result) {
         if (isset($result['info'])) {
             $this->saveToDb($result);
         } else {
             foreach ($result as $k => $v) {
                 $this->saveToDb($v, $k);
             }
         }
     }
     return $result;
 }