用php生成xml文件,移动改文件时 rename 错误


   
  //更新站点地图索引地图
  
$count = db_getkey('SELECT COUNT(`id`) FROM `article` WHERE `state`>0');
$page_num=10; //单xml的记录数;
$pages = $count?ceil($count/$page_num):0;
if($pages){
$sitemapindex = new XMLWriter();
$sitemapindex->openUri('sitemap.xml');
$sitemapindex->setIndentString('');
$sitemapindex->setIndent(true);
$sitemapindex->startDocument('1.0','utf-8');
$sitemapindex->startElement('sitemapindex');
for ($i=1; $i<=$pages; $i++){
$sitemapindex->startElement('sitemap');
$sitemapindex->startElement('loc');
$sitemapindex->text(URL.'sitemap_'.$i.'.xml');
$sitemapindex->endElement();
$sitemapindex->startElement('lastmod');
$sitemapindex->text(date('Y-m-d'));
$sitemapindex->endElement();
$sitemapindex->endElement();
}
$sitemapindex->endElement();
for($ii=1; $ii<=$pages; $ii++){
$data = db_getrows('SELECT `id`,`gid`,`title`,`ctime` FROM `article` WHERE `state`>0 ORDER BY `id` DESC LIMIT '.($ii*$page_num-$page_num).','.$page_num);
if($data){
$data_xml =array();
foreach($data as $k=>$v){
$data_xml[$k]['loc'] = 'http://www.9696e.com/game/news-gid-'.$data[$k]['gid'].'-aid-'.$data[$k]['id'].'.html';
$data_xml[$k]['content'] = $data[$k]['title'];
$data_xml[$k]['lastmod'] = date('Y-m-d',$data[$k]['ctime']);
$data_xml[$k]['weekly'] = 'weekly';
$data_xml[$k]['priority'] = '0.7';
}
$xml = new XMLWriter();
$xml->openUri('sitemap_'.$ii.'.xml');
$xml->setIndentString(' ');
$xml->setIndent(true);
$xml->startDocument('1.0', 'utf-8');
$xml->startElement('urlset');
foreach ($data_xml as $v){
$xml->startElement('url');
foreach ($v as $kk=>$vv){
$xml->startElement($kk);
$xml->text($vv);
$xml->endElement();
}
$xml->endElement();
}
$xml->endElement();
rename('sitemap_'.$ii.'.xml','sitemap/sitemap_'$ii.'.xml');
$HTML = json_encode(array('msg'=>'更新成功','bool'=>1));
}
}
}

文件可以正常生成。但是移动不可以。如果是用copy(),unlink()则不能删除最后一个文件。
@lazyboy @brayden @亚飞正传

xml php

玩死馆里猿 10 years, 11 months ago

首先你确定你在sitemap这个目录下有权限吗

Y典娜·囧死 answered 10 years, 11 months ago

Your Answer