+ -
当前位置:首页 → 问答吧 → 我的一个简单文件类

我的一个简单文件类

时间:2005-09-28

来源:互联网

写的不好,都打算替换了,大家PP^_^
<?
//====================================================
//                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

可以用来生成html吧?

作者: xinge   发布时间: 2006-07-10

不喜欢这样的程序风格,在功能上也太弱了

希望再接再厉吧

作者: hackfan   发布时间: 2006-07-10

热门下载

更多