时时商务社区
标题:
php静态文件生成类实例分析
[打印本页]
作者:
qz234
时间:
2018-2-14 05:50
本文实例讲述了php静态文件生成类。分享给大家供大家参考。
具体实现方法如下:
[U]复制代码[/U] 代码如下:defined('phpjb51') 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")
希望本文所述对大家的php程序设计有所帮助。
您可能感兴趣的文章:
php在线生成ico文件的代码
PHP生成RSS文件类实例
php可生成缩略图的文件上传类实例
php生成zip文件类实例
php生成PDF格式文件并且加密
php提交过来的数据生成为txt文件
PHP生成及获取JSON文件的方法
php生成与读取excel文件
利用PHP生成CSV文件简单示例
php简单读取.vcf格式文件的方法示例
PHP实现生成vcf vcard文件功能类定义与使用方法详解【附demo源码下载】
欢迎光临 时时商务社区 (http://bbs.4435.cn/)
Powered by Discuz! X3.2