/**
  * @return array
  */
 public function convertToBase64()
 {
     $base64 = '';
     if (isset($_SERVER['CONTENT_LENGTH']) && (int) $_SERVER['CONTENT_LENGTH'] > min(Utils::iniGetBytes('post_max_size'), 1000000)) {
         return array('error' => 'File too large - max size is 1 MB');
     } else {
         $base64 .= 'data:' . FsUtils::getMimeType($this->resource['tmp_name']) . ';' . 'base64,' . base64_encode(file_get_contents($this->resource['tmp_name']));
         $oldFileSize = filesize($this->resource['tmp_name']);
         $newFileSize = strlen($base64);
         $sizeDiff = $newFileSize * 100 / $oldFileSize - 100;
         $diffPrefix = $sizeDiff < 0 ? '-' : '+';
         $sizeDiff = $diffPrefix . (string) round($sizeDiff, 1) . '%';
         $msg = basename($this->resource['name']) . ', ' . 'was ' . FsUtils::formatFileSize($oldFileSize) . ', ' . 'now ' . FsUtils::formatFileSize($newFileSize) . ' ' . '(' . $diffPrefix . (string) round($sizeDiff, 1) . '%, ' . 'about +30% is normal)';
         return array('success' => $msg, 'base64' => $base64);
     }
 }
 /**
  * Verify paths and encode the file
  * 
  * @param string $basedir
  * @param string $source
  * @throws \tao_models_classes_FileNotFoundException
  * @throws \common_exception_Error
  * @return string
  */
 protected static function secureEncode($basedir, $source)
 {
     $components = parse_url($source);
     if (!isset($components['scheme'])) {
         // relative path
         if (\tao_helpers_File::securityCheck($source, false)) {
             if (file_exists($basedir . $source)) {
                 return 'data:' . FsUtils::getMimeType($basedir . $source) . ';' . 'base64,' . base64_encode(file_get_contents($basedir . $source));
             } else {
                 throw new \tao_models_classes_FileNotFoundException($source);
             }
         } else {
             throw new \common_exception_Error('Invalid source path "' . $source . '"');
         }
     } else {
         // url, just return it as is
         return $source;
     }
 }
 public function getBase64()
 {
     //TODO Resize the image
     if ($this->hasRequestParameter('upload')) {
         $filename = $this->getRequestParameter('upload');
         $return['base64'] = 'data:' . FsUtils::getMimeType($filename) . ';base64,' . base64_encode(file_get_contents($filename));
     } else {
         $return['base64'] = Template::img('tao-logo.png', 'tao');
     }
     $this->returnJson($return);
 }