97 if ($create ===
true) {
127 if (touch($this->
pwd())) {
144 public function open($mode =
'r', $force =
false)
146 if (!$force && is_resource($this->handle)) {
149 if ($this->
exists() ===
false) {
150 if ($this->
create() ===
false) {
154 $this->handle = fopen($this->
pwd(), $mode);
155 if (is_resource($this->handle)) {
171 public function read($bytes =
false, $mode =
'rb', $force =
false)
174 if ($this->lock !== null) {
175 if (flock($this->handle, LOCK_SH) ===
false) {
179 if ($bytes ===
false) {
180 $success = file_get_contents($this->
pwd());
182 if ($this->
open($mode, $force) ===
true) {
183 if (is_int($bytes)) {
184 $success = fread($this->handle, $bytes);
187 while (!feof($this->handle)) {
188 $data .= fgets($this->handle, 4096);
190 $success = trim($data);
194 if ($this->lock !== null) {
195 flock($this->handle, LOCK_UN);
210 public function offset($offset =
false, $seek = SEEK_SET)
212 if ($offset ===
false) {
213 if (is_resource($this->handle)) {
214 return ftell($this->handle);
217 if ($this->
open() ===
true) {
218 return fseek($this->handle, $offset, $seek) === 0;
236 if (substr(PHP_OS, 0, 3) ==
'WIN') {
239 return strtr($data, array(
"\r\n" => $lineBreak,
"\n" => $lineBreak,
"\r" => $lineBreak));
252 public function write($data, $mode =
'w', $force =
false)
255 if ($this->
open($mode, $force) ===
true) {
256 if ($this->lock !== null) {
257 if (flock($this->handle, LOCK_EX) ===
false) {
261 if (fwrite($this->handle, $data) !==
false) {
264 if ($this->lock !== null) {
265 flock($this->handle, LOCK_UN);
280 public function append($data, $force =
false)
282 return $this->
write($data,
'a', $force);
293 if (!is_resource($this->handle)) {
296 return fclose($this->handle);
305 public function delete()
308 return unlink($this->
pwd());
321 if ($this->
info == null) {
322 $this->
info = pathinfo($this->
pwd());
324 if (!isset($this->
info[
'filename'])) {
325 $this->
info[
'filename'] = $this->
name();
338 if ($this->
info == null) {
341 if (isset($this->
info[
'extension'])) {
342 return $this->
info[
'extension'];
355 if ($this->
info == null) {
358 if (isset($this->
info[
'extension'])) {
359 return basename($this->
name,
'.' . $this->
info[
'extension']);
360 } elseif ($this->
name) {
382 return preg_replace(
'/[^\w\.-]+/',
'_', basename(
$name,
$ext));
393 public function md5($maxsize = 5)
395 if ($maxsize ===
true) {
396 return md5_file($this->
pwd());
398 $size = $this->
size();
399 if ($size && $size < ($maxsize * 1024) * 1024) {
400 return md5_file($this->
pwd());
425 $exists = is_file($this->
pwd());
438 return substr(sprintf(
'%o', fileperms($this->
pwd())), -4);
452 return filesize($this->
pwd());
465 return is_writable($this->
pwd());
476 return is_executable($this->
pwd());
487 return is_readable($this->
pwd());
498 return fileowner($this->
pwd());
512 return filegroup($this->
pwd());
526 return fileatime($this->
pwd());
540 return filemtime($this->
pwd());
static getHandler($name= 'file', $path=false, $create=false, $mode=null)
read($bytes=false, $mode= 'rb', $force=false)
append($data, $force=false)
offset($offset=false, $seek=SEEK_SET)
open($mode= 'r', $force=false)
safe($name=null, $ext=null)
__construct($path, $create=false, $mode=0755)
write($data, $mode= 'w', $force=false)