private function detectMimeType($file)
    {
        $fileParts = explode('.', $file);
        $extension = array_pop($fileParts);
        $extension = strtolower($extension);

        if (array_key_exists($extension, $this->mimeTypes)) {
            return $this->mimeTypes[$extension];
        }

        if (function_exists('finfo_open')) {
            $finfo    = finfo_open(FILEINFO_MIME_TYPE);
            $mimeType = finfo_file($finfo, $file);
            finfo_close($finfo);

            return $mimeType;
        }

        return 'application/octet-stream';
    }