From 642445b527ed13e41974517c2af4bbea603dda0b Mon Sep 17 00:00:00 2001 From: lat9 Date: Wed, 7 Feb 2024 18:49:47 -0500 Subject: [PATCH] #35: Determine number of records in gzipped xml files --- sitemapXML/YOUR_Admin/sitemapxml.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/sitemapXML/YOUR_Admin/sitemapxml.php b/sitemapXML/YOUR_Admin/sitemapxml.php index 224f83d..5a235a5 100644 --- a/sitemapXML/YOUR_Admin/sitemapxml.php +++ b/sitemapXML/YOUR_Admin/sitemapxml.php @@ -275,15 +275,30 @@ $comments .= ' ' . TEXT_SITEMAPXML_FILE_LIST_COMMENTS_IGNORED; } if ($f['size'] > 0) { - $fp = fopen($file, 'r'); + // ----- + // PHP functions used to read the file depend on whether it was + // gzipped or not. + // + if (pathinfo($file, PATHINFO_EXTENSION) === 'gz') { + $fopen = 'gzopen'; + $read_only = 'rb9'; + $fread = 'gzread'; + $fclose = 'gzclose'; + } else { + $fopen = 'fopen'; + $read_only = 'r'; + $fread = 'fread'; + $fclose = 'fclose'; + } + $fp = $fopen($file, $read_only); if ($fp === false) { $items = 'Error!!!'; } else { $contents = ''; while (!feof($fp)) { - $contents .= fread($fp, 8192); + $contents .= $fread($fp, 8192); } - fclose($fp); + $fclose($fp); if (strpos($contents, '') !== false) { $type = TEXT_SITEMAPXML_FILE_LIST_TYPE_URLSET; $items = substr_count($contents, '');