/** * Returns the mime type of a file. * * @param string $filename * @return string */ public static function getMimeType($filename) { if (self::$finfo === null) { if (!class_exists('\\finfo', false)) { return ''; } self::$finfo = new \finfo(FILEINFO_MIME_TYPE); } return self::$finfo->file($filename); }
/** * Returns memory limit in bytes. * * @return integer */ public static function getMemoryLimit() { if (self::$memoryLimit === null) { self::$memoryLimit = 0; $memoryLimit = ini_get('memory_limit'); // no limit if ($memoryLimit == -1) { self::$memoryLimit = -1; } // completely numeric, PHP assumes byte if (is_numeric($memoryLimit)) { self::$memoryLimit = $memoryLimit; } // PHP supports 'K', 'M' and 'G' shorthand notation if (preg_match('~^(\\d+)([KMG])$~', $memoryLimit, $matches)) { switch ($matches[2]) { case 'K': self::$memoryLimit = $matches[1] * 1024; break; case 'M': self::$memoryLimit = $matches[1] * 1024 * 1024; break; case 'G': self::$memoryLimit = $matches[1] * 1024 * 1024 * 1024; break; } } } return self::$memoryLimit; }