signer
新手上路

UID 90055
精华
0
积分 16
帖子 19
金钱 16 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2007-3-25
状态 离线
|
[广告]: q
m
新手写的文件读写的类(静态),请高手们指教
静态页面,很多人用ob_...... 如果有很多个页面,那每个页面都要ob....那。。。。
直接这样读写,会不会好点,请教。。。
<?php
error_reporting(2047);
class staticpage {
var $sourcepath;
var $sourcefilename;
var $openmode;// 'w+','w'......
var $objpath;
var $objfilename;
function setsourcefile($path,$filename) {
$this->sourcepath = $path;
$this->sourcefilename = $filename;
}
function setobjfile($path,$filename,$openmode) {
$this->openmode = $openmode;
$this->objpath = $path;
$this->objfilename = $filename;
}
function fileputcontents() {
$sourcefilecontents = file_get_contents($this->sourcepath.'/'.$this->sourcefilename);//php4,php5
$phpversion = substr(phpversion(),0,1);
if($phpversion <= '4') {
$fp = fopen($this->objpath.'/'.$this->objfilename,$this->openmode);//php4
return fwrite($fp,$sourcefilecontents);
fclose($fp);
} else {
return file_put_contents($this->objpath.'/'.$this->objfilename,$sourcefilecontents);//php5
}
}
//
}
$tmp = new staticpage;
$tmp->setsourcefile('http://www.sina.com.cn','');
$tmp->setobjfile('./','test.html','w+');
$tmp->fileputcontents();
?>
|
|