public static function is_tgz_file($archivefile) {
        if (is_a($archivefile, 'stored_file')) {
            $fp = $archivefile->get_content_file_handle();
        } else {
            $fp = fopen($archivefile, 'rb');
        }
        $firstbytes = fread($fp, 2);
        fclose($fp);
        return ($firstbytes[0] == "\x1f" && $firstbytes[1] == "\x8b");
    }