在生成静态页面的过程中,发现自动生成的过程,如果是频繁修改的页面,就会逐步递增,以至于生成数量极其庞大的文件夹,试想了一下,如果在我生成的时候自动 覆盖 或删除旧文件,然后生成新的 静态HTML ,如下:有段代码:麻烦各位帮小弟修改一下,学习中····························
<?php
  require_once("1.php");//引用conn.php,连接数据库
  //以下建立一文本文档,其值自动计数
header("Content-type: text/html; charset=gb2312");
$action = $_POST['hdd'];
if($action == "sendaction"){
  $title=$_POST["title"];
  $content=$_POST["content"]; //获得表单变量    //以下建立一文本文档,其值自动计数
  $countfile="count.txt";
  if(!file_exists($countfile))
  {
  fopen($countfile,"w"); //如果此文件不存在,则自动建立一个
  }
  $fp=fopen($countfile,"r");
  $num=fgets($fp,20);
  $num=$num+1; //每次其值自动加一
  fclose($fp);
  $fp=fopen($countfile,"w");
  fwrite($fp,$num);
  fclose($fp);
//利用上面自动计数的值获得HTML的路径$path
  $houzui=".html";
  $path=$num.$houzui;
if(file_exists($path)){
   unlink($path);    //那肯定是真,怎么办?
}else{
   $sql = "insert into input (title,content,path) values ('".$title."','".$content."','".$path."')";
  $query=mysql_query($sql);
  /*********************************/
  $fp=fopen("axiebin.htm","r");
  $str=fread($fp,filesize("axiebin.htm"));
  $str=str_replace("{title}",$title,$str);
  $str=str_replace("{content}",$content,$str);
  fclose($fp);  
  $handle=fopen($path,"w");
  fwrite($handle,$str);
  fclose($handle);
  }
}
由于不断的生成新的HTML 文件数量机器庞大,先征求各位 删除文件的方法???
echo "<a href=$path target=_blank> 查看刚才添加的新闻 </a>";?>
<form method="post" action="2.php">
<input type="hidden" name="hdd" value="sendaction">
  新闻标题:<input type="text" name="title" size="20"><br>
  新闻内容:<textarea name="content" cols="15" rows="10"></textarea><br>
  <input type="submit" name="提交" name="sub">
  </form>