protected function determineFilename($originalFilename, array $mediaFileInfo)
    {
        if (is_null($originalFilename) || ! isset($originalFilename) || is_file(sys_get_temp_dir() . '/' . $originalFilename)) {
            //Need to create a unique file name as file either exists or we couldn't determine it.
            //Create temp file in system folder.
            $uniqueFilename = tempnam(sys_get_temp_dir(), 'tg');
            //Add file extension
            rename($uniqueFilename, $uniqueFilename . '.' . $mediaFileInfo['fileextension']);

            $mediaFileInfo['filepath'] = $uniqueFilename . '.' . $mediaFileInfo['fileextension'];

        } else {
            $mediaFileInfo['filepath'] = sys_get_temp_dir() . '/' . $originalFilename;
        }

        return $mediaFileInfo;
    }