国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php靜態文件生成類

2024-09-04 11:44:11
字體:
來源:轉載
供稿:網友
  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. //開源代碼Vevb.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完成!";

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新河县| 公主岭市| 三亚市| 卢氏县| 昭平县| 南木林县| 甘德县| 承德县| 洛川县| 蒙阴县| 永寿县| 绩溪县| 铁岭县| 磐安县| 中宁县| 福鼎市| 东兰县| 上饶市| 河源市| 永康市| 临颍县| 论坛| 荃湾区| 曲阜市| 云林县| 固镇县| 铁岭市| 汨罗市| 正镶白旗| 泸西县| 保定市| 西吉县| 龙门县| 祁门县| 万宁市| 年辖:市辖区| 丹凤县| 鄯善县| 香格里拉县| 古丈县| 宁城县|