![]() |
|
首页 │ Apache │ Linux│ Java│ MySQL│ 注册│帮助 | |||
[php]
<?php
// +-----------------------------------------------------------------------
// | iZz :: File
// +-----------------------------------------------------------------------
// | Copyright (c) 2000-2002 iZz Studio
// +-----------------------------------------------------------------------
// | This source file is created by iZz Studio. And this file is not
// | public and not a open source file. If you get this file, and not
// | , please contact us by emailing to justdn@justdn.com.
// |
// |
// |
// |
// |
// +-----------------------------------------------------------------------
// | Author(s):
// |
// |
// +-----------------------------------------------------------------------
//
// $Id: iZzFile.php,v 1.1 2002/10/31 11:16:21 Beijing Time Zone $
//-------------------------------------------------------------------------
//
//使用方法:
//只读
ifile = new iFile('test.txt','r');
//读写
ifile = new iFile('test.txt','w');
//快读
ifile = new iFile('test.txt','dr');
//快写
ifile = new iFile('test.txt','w','测试一下咯');
//读取文件内容
ifile->getFileData();
//显示读取/快读数据:echo $ifile->Data;
//写入文件内容
ifile->WriteFile('测试一下咯',3);
//关闭文件句柄
ifile->ColseFile();
//
//注意:写入/快写后自动关闭文件句柄.
//-------------------------------------------------------------------------
class iFile {
var $Fp;
var $Pipe; //(fopen,popen)(f,p)
var $File;
var $OpenMode; //(r,r+,w,w+,a,a+,b)
var $Data;
function iFile($File,$Mode = 'r',$Data4Write='',$Pipe = 'f'){
$this -> File = $File;
$this -> Pipe = $Pipe;
if($Mode == 'dr'){
$this -> openMode = 'r';
$this -> OpenFile();
$this -> getFileData();
}else{
$this -> openMode = $Mode;
$this -> OpenFile();
}
if($this->OpenMode=='w'&&$Data4Write!=''){
$this -> WriteFile($Data4Write,$Mode = 3);
}
}
function OpenFile(){
if ($this -> openMode == 'r'||$this -> openMode == 'r+'){
if($this->CheckFile()){
if ($this -> Pipe == 'f') {
$this->Fp = fopen($this -> File, $this -> OpenMode);
} elseif ($Pipe == 'p') {
$this->Fp = popen($this -> File, $this -> OpenMode);
}else{
Die("Check The OpenFile Pipe,It can be 'f' or 'p'./请检查文件打开参数3,f:fopen(),p
oen().");
}
} else {
Die("Access Error: Check $File is exist./文件访问错误,请检查文件是否存在!");
}
} else {
if ($this -> Pipe == 'f') {
$this->Fp = fopen($this -> File, $this -> OpenMode);
} elseif ($Pipe == 'p') {
$this->Fp = popen($this -> File, $this -> OpenMode);
} else {
Die("Check The OpenFile Pipe,It can be 'f' or 'p'./请检查文件打开参数3,f:fopen(),p
oen().");
}
}
}
function CloseFile(){
if ($this->Pipe == 'f'){
@fclose($this->Fp);
} else {
@pclose($this->Fp);
}
}
function getFileData(){
@flock($this->Fp, 1);
$Content = fread($this->Fp, filesize($this->File));
$this->Data = $Content;
}
function CheckFile(){
if (file_exists($this -> File)) { return true; } else { return false; }
}
function WriteFile($Data4Write,$Mode = 3){
@flock($this->Fp,$Mode);
fwrite($this->Fp,$Data4Write);
$this->CloseFile();
return true;
}
}
?>
[/php]

