标签:
<?php class gfile{ private $path; private $fp; function __construct(String $filepath){ if(isset($filepath)){ if(file_exists($filepath)){ $this->path = $filepath; }else{ throw new Exception("undefind path", 1); } }else{ throw new Exception("undefind parm", 1); } } public function setVal(String $val){ $this->fp = fopen($this->path,"w+"); flock($this->fp, LOCK_EX) ; $val ? $val : 0; fwrite($this->fp,$val); } public function getVal(){ $this->fp = fopen($this->path,"r"); flock($this->fp, LOCK_EX) ; return fread($this->fp, filesize($this->path)); } function __destruct(){ if($this->fp){ flock($this->fp, LOCK_UN) ; fclose($this->fp); } } } $gfile = new gfile("lid.txt"); echo $gfile->getVal(); ?>
标签:
原文地址:http://www.cnblogs.com/bin-pureLife/p/5105640.html