php教程静态文件生成类
define('php教程ox') or die(header("http/1.1 403 not禁止"));
class include_createstatic
{
private $htmlpath = '';
private $path = '';
public $monthpath = '';
private $listpath = '';
private $content = '';
private $filename = '';
private $extname = '.html';
public function createhtml($type,$desname,$content)
{
$this->htmlpath = getappinf('htmlpath');
if (!file_exists($this->htmlpath))
{
@mkdir($this->htmlpath);
}
$this->path = $this->htmlpath.$this->monthpath.'/';
if (!file_exists($this->path))
{
@mkdir($this->path);
}
$this->listpath = $this->htmlpath.'list/';
if (!file_exists($this->listpath))
{
@mkdir($this->listpath);
}
开关($type)
{
case 'index':
$this->文件名 = $desname;
休息;
案例“列表”:
$this->文件名 = $this->listpath.$desname;
休息;
case 'view':
$this->filename = $this->path.$desname;
休息;
}
$this->文件名.= $this->扩展名;
$this->content = $content;
}
public function write()
{
$fp=fopen($this->文件名,'wb') ;
if (!is_writable($this->filename))
{
返回 false;
}
if (!fwrite($fp,$this->content))
{
返回 false;
}
fclose($fp);
return $this->文件名;
}
}//方法二
if(file_exists("./index.htm"))//看静态index.htm文件是否存在
{
$时间=时间();
//文件修改时间和现在时间外?的话,直接指向htm文件,否则重新生成htm
if(time-filemtime("./index.htm"){
header("位置:classhtml/main.htm");
}
}
//在你的开始处加入ob_start();
ob_start();
//首页内容,就是你的动态部分了
//在末尾加入ob_end_clean(),并将本页输出到一个变量中
$temp=ob_get_contents();
ob_end_clean();
// 写入文件
$fp=fopen("./index.htm",'w');
fwrite(fp,temp) or die('写文件错误');
//echo"生成html完成!";