|
<br> 我的具体实现的例子 <BR> 为了帮助大家有个感性认识,这里我给出在我的主页上实现的基于文件处理的方法。只有主要的处理代码,不完整。 <BR><TABLE cellSpacing=0 cellPadding=0 width="85%"><TBODY><TR><TD style="BORDER-RIGHT: rgb(0,0,0) 1px groove; BORDER-TOP: rgb(0,0,0) 1px groove; BORDER-LEFT: rgb(0,0,0) 1px groove; BORDER-BOTTOM: rgb(0,0,0) 1px groove" bgColor=#eeeeee> <? <BR> 1 $tmpfile="../tmp/".basename($REQUEST_URI); <BR> 2 $tmpfile=str_replace("?", "_", $tmpfile); <BR> 3 $tmpfile=str_replace("&", "_", $tmpfile); <BR> 4 if(file_exists($tmpfile)) <BR> 5 { <BR> 6 $cflag=false; <BR> 7 $dtmp=filemtime($tmpfile); <BR> 8 $itmp=filemtime($incfile); <BR> 9 $cflag=$cflag | ($dtmp < $itmp); <BR> 10 $ctmp=filemtime(basename($PHP_SELF)); <BR> 11 $cflag=$cflag | ($dtmp < $ctmp); <BR> 12 $ttmp=filemtime("template/content.ihtml"); <BR> 13 $cflag=$cflag | ($dtmp < $ttmp); <BR> 14 } <BR> 15 else <BR> 16 $cflag=true; <BR> 17 <BR> 18 if(!$cflag) //使用存在的文件 <BR> 19 { <BR> 20 readfile($tmpfile); <BR> 21 exit; <BR> 22 } <BR> 23 <BR> 24 //创建新的文件 <BR> 25 include "template.class.php3"; <BR> 26 <BR> 27 $fp=fopen($incfile, "r"); <BR> 28 $content=fread($fp, filesize($incfile)); <BR> 29 fclose($fp); <BR> 30 <BR> 31 //下面进行模版处理 <BR> 32 $t = new Template("template", "keep"); <BR> 33 <BR> 34 $t->set_file("contentfile","content.ihtml"); <BR> 35 <BR> 36 $t->set_var( <BR> 37 array( <BR> 38 "content"=>$content <BR> 39 )); <BR> 40 <BR> 41 $t->parse("outputcontent","contentfile"); <BR> 42 <BR> 43 $fp=fopen($tmpfile, "w"); <BR> 44 if($fp) <BR> 45 { <BR> 46 flock($fp, 3); <BR> 47 fwrite($fp, $t->get_var("outputcontent")); <BR> 48 flock($fp, 1); <BR> 49 fclose($fp); <BR> 50 } <BR> 51 $t->p("outputcontent"); <BR> ?> </TD></TR></TBODY></TABLE><BR><BR> 先向大家介绍一下我的目录结构: <BR> /---bin/ 执行程序目录 <BR> | |--content.php3 用于处理文件显示的程序 <BR> | |--template/ 用于存放模板文件的目录 <BR> | |---content.ihtml 模板文件 <BR> |-docs/ 数据文件 <BR> |-tmp/ 存放缓冲文件 <br><br> |
|