我的一个简单文件类
时间:2005-09-28
来源:互联网
<?
//====================================================
// FileName:myfile.class.php
// Summary: 文件类
// Author: feifengxlq
// CreateTime: 2005-7-19
// LastModifed:
// copyright (c)2005 xlq.100steps.net [email protected]
// 使用范例:
//$myfile=new myfile();
//$str=$myfile->read('test.php');
//$myfile->write('../uploadfiles/test2.php',$str);
//==========================================================
class myfile{
var $debug;
var $over;
var $handlel;
var $error;
function myfile($over=false,$debug=true)
{
$this->setover($over);
$this->setdebug($debug);
}
function setover($over)
{
$this->over=$over;
}
function setdebug($debug)
{
$this->debug=$debug;
}
function open($filename,$mode)
{
if($this->handle=@fopen($filename,$mode))
{
return $this->handle;
}else
{
if($this->debug) error('打开文件失败!');
$this->error[count($this->error)]='打开文件失败!';
return false;
}
}
function iswrite($filename)
{
if(!is_writable($filename))
{
if($this->debug) error('文件不可写');
$this->error[count($this->error)]='文件不可写!';
return false;
}
return true;
}
function close()
{
@fclose($this->handle);
}
function check($filename)
{
if(!$this->over)
{
if(file_exists($filename))
{
if($this->debug) error('文件已经存在,不能覆盖!');
$this->error[count($this->error)]='文件已经存在,不能覆盖!';
return false;
}
return true;
}
}
function writefile($content)
{
if(!@fwrite($this->handle,$content))
{
if($this->debug) error('数据写入文件出错!');
$this->error[count($this->error)]='数据写入文件出错!';
return false;
}
return true;
}
function write($filename,$content='',$add=false)
{
$mode=($add)?'ab':'wb';
if(!$add)
$this->check($filename);
else
$this->iswrite($filename);
$this->open($filename,$mode);
$this->writefile($content);
$this->close();
}
function read($filename)
{
return @file_get_contents($filename);
}
function error()
{
return $this->error;
}
}
?>
作者: feifengxlq 发布时间: 2005-09-27
作者: seraph 发布时间: 2005-09-28
能把查找和另外一些功能放进去么?
作者: Phzzy 发布时间: 2005-09-28
引用:
原帖由 Phzzy 于 2005-9-28 12:54 发表顶一下~~~
能把查找和另外一些功能放进去么?
文件的查询我都放在另外一个类里面~mydir.class.php~
不过这个的确也不完善~要换了,让大家见笑了~
作者: feifengxlq 发布时间: 2005-09-28
现在找不着了...而且代码太多...俺也没看完
作者: Phzzy 发布时间: 2005-09-29
作者: xinge 发布时间: 2006-07-10
希望再接再厉吧
作者: hackfan 发布时间: 2006-07-10
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28