一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

php 生成静态页面 fopen fwrite

时间:2009-04-15 编辑:简简单单 来源:一聚教程网

function makeHtml($msgContent,$filePath,$fileName){//生成html文件  


  if(!is_dir($filePath)){@mkdir($filePath);}   


  $handle = fopen(str_replace('\','../',$filePath.$fileName),'w+') or die("can't create file!$fileName");


  fwrite($handle,$msgContent);


  fclose($handle);  


}

function md5_filename($fileid,$fileztype,$fileuid){//文件加密方法
   return md5($fileid.$fileztype.$fileuid).'.htm';
}
 
function getSql(){//一次多少生成htm文件
  global $limit,$start,$id;
  $sysType = '';  
  if( !empty( $id ) ){
   $sysType = "And systype = $id";
  }
  $sql = "select * from filecontent where siteindex=1 $sysType limit $start,$limit";
  $result = mysql_query($sql) or die('Query error');
   while( $rs = mysql_fetch_array($result) ){
     $fileName =md5_filename($rs[0],$rs['z_type'],$rs['filesendid']);
     $path = get_path($rs['systype']).$rs['z_type'].'/';    
     $parent = substr(getcwd(),0,strrpos(getcwd(),'\'));    
     $filePath =$parent.'\'.$path;
     makeHtml($rs['content'],$filePath,$fileName);
   }
   mysql_free_result($result);
}
 

$info = "";
 
  if($start>$end){
   die('完成所有生成任务!');
  } else {
   getSql(); 
   echo $info;  
  }

热门栏目