最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php 静态文件生成类
时间:2022-06-24 18:34:02 编辑:袖梨 来源:一聚教程网
php教程 静态文件生成类
defined('php教程ox') or die(header("http/1.1 403 not forbidden"));
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);
}
switch ($type)
{
case 'index':
$this->filename = $desname;
break;
case 'list':
$this->filename = $this->listpath.$desname;
break;
case 'view':
$this->filename = $this->path.$desname;
break;
}
$this->filename .= $this->extname;
$this->content = $content;
}
public function write()
{
$fp=fopen($this->filename,'wb');
if (!is_writable($this->filename))
{
return false;
}
if (!fwrite($fp,$this->content))
{
return false;
}
fclose($fp);
return $this->filename;
}
}//方法二
if(file_exists("./index.htm"))//看静态index.htm文件是否存在
{
$time=time();
//文件修改时间和现在时间相差?的话,直接导向htm文件,否则重新生成htm
if(time-filemtime("./index.htm")< 600)
{
header("location: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完成!";
相关文章
- 王者荣耀侦探能力大测试攻略 王者荣耀侦探能力大测试怎么过 11-22
- 无期迷途主线前瞻兑换码是什么 11-22
- 原神欧洛伦怎么培养 11-22
- 炉石传说网易云音乐联动怎么玩 11-22
- 永劫无间手游确幸转盘怎么样 11-22
- 无期迷途主线前瞻兑换码是什么 无期迷途主线前瞻直播兑换码介绍 11-22