/** * @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); } }