123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- class FSTools_File
- {
-
- protected $name;
-
- protected $handle = false;
-
- protected $fs;
-
- public function __construct($name, $fs = false)
- {
- $this->name = $name;
- $this->fs = $fs ? $fs : FSTools::singleton();
- }
-
- public function getName() {return $this->name;}
-
- public function getDirectory() {return $this->fs->dirname($this->name);}
-
- public function get()
- {
- return $this->fs->file_get_contents($this->name);
- }
-
- public function write($contents)
- {
- return $this->fs->file_put_contents($this->name, $contents);
- }
-
- public function delete()
- {
- return $this->fs->unlink($this->name);
- }
-
- public function exists()
- {
- return $this->fs->is_file($this->name);
- }
-
- public function getMTime()
- {
- return $this->fs->filemtime($this->name);
- }
-
- public function chmod($octal_code)
- {
- return @$this->fs->chmod($this->name, $octal_code);
- }
-
- public function open($mode)
- {
- if ($this->handle) $this->close();
- $this->handle = $this->fs->fopen($this->name, $mode);
- return true;
- }
-
- public function close()
- {
- if (!$this->handle) return false;
- $status = $this->fs->fclose($this->handle);
- $this->handle = false;
- return $status;
- }
-
- public function getLine($length = null)
- {
- if (!$this->handle) $this->open('r');
- if ($length === null) return $this->fs->fgets($this->handle);
- else return $this->fs->fgets($this->handle, $length);
- }
-
- public function getChar()
- {
- if (!$this->handle) $this->open('r');
- return $this->fs->fgetc($this->handle);
- }
-
- public function read($length)
- {
- if (!$this->handle) $this->open('r');
- return $this->fs->fread($this->handle, $length);
- }
-
- public function put($string)
- {
- if (!$this->handle) $this->open('a');
- return $this->fs->fwrite($this->handle, $string);
- }
-
- public function eof()
- {
- if (!$this->handle) return true;
- return $this->fs->feof($this->handle);
- }
- public function __destruct()
- {
- if ($this->handle) $this->close();
- }
- }
|