VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > PHP >
  • php静态文件生成类

  1. class include_createstatic              
  2. {             
  3.                  
  4.     private $htmlpath = '';             
  5.     private $path = '';             
  6.     public $monthpath = '';             
  7.     private $listpath = '';             
  8.     private $content = '';             
  9.     private $filename = '';             
  10.     private $extname = '.html';             
  11.                  
  12.     public function createhtml($type,$desname,$content)             
  13.     {             
  14.         $this->htmlpath = getappinf('htmlpath');             
  15.         if (!file_exists($this->htmlpath))             
  16.         {             
  17.             @mkdir($this->htmlpath);             
  18.         }             
  19.         $this->path = $this->htmlpath.$this->monthpath.'/';             
  20.         if (!file_exists($this->path))             
  21.         {             
  22.             @mkdir($this->path);             
  23.         }             
  24.         $this->listpath = $this->htmlpath.'list/';             
  25.         if (!file_exists($this->listpath))             
  26.         {             
  27.             @mkdir($this->listpath);             
  28.         }             
  29.         switch ($type)             
  30.         {             
  31.             case 'index':             
  32.                 $this->filename = $desname;             
  33.                 break;             
  34.             case 'list':             
  35.                 $this->filename = $this->listpath.$desname;             
  36.                 break;             
  37.             case 'view':             
  38.                 $this->filename = $this->path.$desname;             
  39.                 break;             
  40.         }             
  41.         $this->filename .= $this->extname;             
  42.         $this->content = $content;             
  43.     }             
  44.                  
  45.     public function write()             
  46.     {             
  47.         $fp=fopen($this->filename,'wb');             
  48.         if (!is_writable($this->filename))             
  49.         {             
  50.             return false;             
  51.         }             
  52.         if (!fwrite($fp,$this->content))             
  53.         {             
  54.             return false;             
  55.         }             
  56.         fclose($fp);             
  57.         return $this->filename;             
  58.     }             
  59. }       
  60.  
  61. //方法二 
  62.  
  63. if(file_exists("./index.htm"))//看静态index.htm文件是否存在  
  64. {  
  65. $time=time();  
  66. //文件修改时间和现在时间相差?的话,直接导向htm文件,否则重新生成htm  
  67. if(time-filemtime("./index.htm")< 600)  
  68. {  
  69. header("location:classhtml/main.htm");  
  70. //开源代码phpfensi.com 
  71. }  
  72. //在你的开始处加入ob_start();  
  73. ob_start();  
  74. //首页内容,就是你的动态部分了  
  75. //在结尾加入ob_end_clean(),并把本页输出到一个变量中  
  76. $temp=ob_get_contents();  
  77. ob_end_clean();  
  78. //写入文件  
  79. $fp=fopen("./index.htm",'w');  
  80. fwrite(fp,temp) or die('写文件错误');  
  81. //echo"生成html完成!";
  82.  

出处:http://www.phpfensi.com/php/20140909/5137.html


相关教程