当前位置:编程学习 > php >>

php 生成静态页面 fopen fwrite

这个是昨天写的一个简单的用仿dedecms风格的生成静态页面的php生成静态页面文件程序代码哦,只是简单的。

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 = "<script language="javascript">
   var pgo =0;
   function JumpUrl(){    
    document.write('己生成文件<a href=make_html.php?id=$id&start=$start&limit=$limit&end=$end>如果浏览器无反应请点击这里</a>');
    location='make_html.php?id=$id&start=$start&limit=$limit&end=$end';    
   }
   setTimeout('JumpUrl()',100);
   </script>";
 
  if($start>$end){
   die('完成所有生成任务!');
  } else {
   getSql(); 
   echo $info;  
  }

补充:Php教程,Php入门 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,