我正在创建一个系统来为我正在开发的应用程序生成sitemaps,生成sitemaps的要求之一是,每个sitemap的文件大小不应该超过10 be (10,485,760字节),这可以看到这里。
这是我创建站点地图的代码:
$fp = fopen($this->getSitemapPath() . $filename, 'w');
fwrite($fp, $siteMap->__toString());
fclose($fp);方法$siteMap->__toString()最多包含50000个链接。
是否有方法在调用函数fwrite之前检查结果文件大小?
发布于 2016-10-07 12:43:16
当然,在将字符串写入文件之前,可以使用mb_strlen获取字符串的长度。
$contents = $siteMap->__toString();
if(mb_strlen($contents, '8bit') >= 10485760) {
echo "Oops, this is too big";
} else {
fwrite($fp, $contents);
}https://stackoverflow.com/questions/39917559
复制相似问题