2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Convenience class for reading, writing and appending to files.
|
|
|
|
*
|
2010-10-03 16:38:58 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.libs
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 0.2.9
|
2009-11-06 06:51:51 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Included libraries.
|
|
|
|
*
|
|
|
|
*/
|
2010-12-08 01:12:50 +00:00
|
|
|
App::uses('Folder', 'Utility');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Convenience class for reading, writing and appending to files.
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.libs
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-18 05:12:00 +00:00
|
|
|
class File {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Folder object of the File
|
|
|
|
*
|
2009-03-17 21:10:28 +00:00
|
|
|
* @var Folder
|
2008-05-30 11:40:08 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $Folder = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Filename
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* file info
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $info = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Holds the file handler resource if the file is opened
|
|
|
|
*
|
|
|
|
* @var resource
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $handle = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* enable locking for file reading and writing
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $lock = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-05 19:21:49 +00:00
|
|
|
/**
|
|
|
|
* path property
|
|
|
|
*
|
|
|
|
* Current file's absolute path
|
|
|
|
*
|
|
|
|
* @var mixed null
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $path = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param string $path Path to file
|
|
|
|
* @param boolean $create Create file if it does not exist (if true)
|
|
|
|
* @param integer $mode Mode to apply to the folder holding the file
|
|
|
|
*/
|
|
|
|
function __construct($path, $create = false, $mode = 0755) {
|
2010-11-13 04:05:44 +00:00
|
|
|
$this->Folder = new Folder(dirname($path), $create, $mode);
|
2008-05-30 11:40:08 +00:00
|
|
|
if (!is_dir($path)) {
|
|
|
|
$this->name = basename($path);
|
|
|
|
}
|
2008-11-05 19:21:49 +00:00
|
|
|
$this->pwd();
|
2010-10-01 03:03:23 +00:00
|
|
|
$create && !$this->exists() && $this->safe($path) && $this->create();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Closes the current file if it is opened
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function __destruct() {
|
|
|
|
$this->close();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Creates the File.
|
|
|
|
*
|
|
|
|
* @return boolean Success
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function create() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$dir = $this->Folder->pwd();
|
|
|
|
if (is_dir($dir) && is_writable($dir) && !$this->exists()) {
|
2008-10-18 20:11:41 +00:00
|
|
|
$old = umask(0);
|
2008-11-05 19:21:49 +00:00
|
|
|
if (touch($this->path)) {
|
2008-10-18 20:11:41 +00:00
|
|
|
umask($old);
|
2008-05-30 11:40:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Opens the current file with a given $mode
|
|
|
|
*
|
|
|
|
* @param string $mode A valid 'fopen' mode string (r|w|a ...)
|
|
|
|
* @param boolean $force If true then the file will be re-opened even if its already opened, otherwise it won't
|
|
|
|
* @return boolean True on success, false on failure
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function open($mode = 'r', $force = false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (!$force && is_resource($this->handle)) {
|
|
|
|
return true;
|
|
|
|
}
|
2008-10-26 22:34:09 +00:00
|
|
|
clearstatcache();
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->exists() === false) {
|
|
|
|
if ($this->create() === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-05 19:21:49 +00:00
|
|
|
$this->handle = fopen($this->path, $mode);
|
2008-05-30 11:40:08 +00:00
|
|
|
if (is_resource($this->handle)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Return the contents of this File as a string.
|
|
|
|
*
|
|
|
|
* @param string $bytes where to start
|
2010-01-25 16:01:05 +00:00
|
|
|
* @param string $mode A `fread` compatible mode.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param boolean $force If true then the file will be re-opened even if its already opened, otherwise it won't
|
|
|
|
* @return mixed string on success, false on failure
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function read($bytes = false, $mode = 'rb', $force = false) {
|
2008-10-15 12:42:03 +00:00
|
|
|
if ($bytes === false && $this->lock === null) {
|
2008-11-05 19:21:49 +00:00
|
|
|
return file_get_contents($this->path);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-10-26 22:34:09 +00:00
|
|
|
if ($this->open($mode, $force) === false) {
|
2008-10-15 12:42:03 +00:00
|
|
|
return false;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-10-15 12:42:03 +00:00
|
|
|
if ($this->lock !== null && flock($this->handle, LOCK_SH) === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (is_int($bytes)) {
|
|
|
|
return fread($this->handle, $bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = '';
|
|
|
|
while (!feof($this->handle)) {
|
|
|
|
$data .= fgets($this->handle, 4096);
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->lock !== null) {
|
|
|
|
flock($this->handle, LOCK_UN);
|
|
|
|
}
|
2008-10-15 12:42:03 +00:00
|
|
|
if ($bytes === false) {
|
|
|
|
$this->close();
|
|
|
|
}
|
2010-05-30 15:16:40 +00:00
|
|
|
return trim($data);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Sets or gets the offset for the currently opened file.
|
|
|
|
*
|
|
|
|
* @param mixed $offset The $offset in bytes to seek. If set to false then the current offset is returned.
|
|
|
|
* @param integer $seek PHP Constant SEEK_SET | SEEK_CUR | SEEK_END determining what the $offset is relative to
|
|
|
|
* @return mixed True on success, false on failure (set mode), false on failure or integer offset on success (get mode)
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function offset($offset = false, $seek = SEEK_SET) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($offset === false) {
|
|
|
|
if (is_resource($this->handle)) {
|
|
|
|
return ftell($this->handle);
|
|
|
|
}
|
|
|
|
} elseif ($this->open() === true) {
|
|
|
|
return fseek($this->handle, $offset, $seek) === 0;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-01-25 16:01:05 +00:00
|
|
|
* Prepares a ascii string for writing. Converts line endings to the
|
|
|
|
* correct terminator for the current platform. If windows "\r\n" will be used
|
|
|
|
* all other platforms will use "\n"
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @param string $data Data to prepare for writing.
|
2010-01-25 16:01:05 +00:00
|
|
|
* @return string The with converted line endings.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-13 02:02:42 +00:00
|
|
|
public static function prepare($data, $forceWindows = false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$lineBreak = "\n";
|
2008-09-12 05:11:34 +00:00
|
|
|
if (DIRECTORY_SEPARATOR == '\\' || $forceWindows === true) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$lineBreak = "\r\n";
|
|
|
|
}
|
|
|
|
return strtr($data, array("\r\n" => $lineBreak, "\n" => $lineBreak, "\r" => $lineBreak));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write given data to this File.
|
|
|
|
*
|
2010-01-25 16:01:05 +00:00
|
|
|
* @param string $data Data to write to this File.
|
|
|
|
* @param string $mode Mode of writing. {@link http://php.net/fwrite See fwrite()}.
|
|
|
|
* @param string $force force the file to open
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return boolean Success
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function write($data, $mode = 'w', $force = false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$success = false;
|
|
|
|
if ($this->open($mode, $force) === true) {
|
2008-10-23 00:10:44 +00:00
|
|
|
if ($this->lock !== null) {
|
|
|
|
if (flock($this->handle, LOCK_EX) === false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fwrite($this->handle, $data) !== false) {
|
|
|
|
$success = true;
|
|
|
|
}
|
|
|
|
if ($this->lock !== null) {
|
|
|
|
flock($this->handle, LOCK_UN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $success;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Append given data string to this File.
|
|
|
|
*
|
|
|
|
* @param string $data Data to write
|
2010-01-25 16:01:05 +00:00
|
|
|
* @param string $force force the file to open
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return boolean Success
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function append($data, $force = false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $this->write($data, 'a', $force);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Closes the current file if it is opened.
|
|
|
|
*
|
|
|
|
* @return boolean True if closing was successful or file was already closed, otherwise false
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function close() {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (!is_resource($this->handle)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return fclose($this->handle);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Deletes the File.
|
|
|
|
*
|
|
|
|
* @return boolean Success
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function delete() {
|
2008-08-05 14:19:29 +00:00
|
|
|
clearstatcache();
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->exists()) {
|
2008-11-05 19:21:49 +00:00
|
|
|
return unlink($this->path);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return false;
|
2008-06-20 20:17:23 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-10-09 03:27:31 +00:00
|
|
|
* Returns the File info.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @return string The File extension
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function info() {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->info == null) {
|
2008-11-05 19:21:49 +00:00
|
|
|
$this->info = pathinfo($this->path);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
if (!isset($this->info['filename'])) {
|
|
|
|
$this->info['filename'] = $this->name();
|
|
|
|
}
|
|
|
|
return $this->info;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns the File extension.
|
|
|
|
*
|
|
|
|
* @return string The File extension
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function ext() {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->info == null) {
|
|
|
|
$this->info();
|
|
|
|
}
|
|
|
|
if (isset($this->info['extension'])) {
|
|
|
|
return $this->info['extension'];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns the File name without extension.
|
|
|
|
*
|
|
|
|
* @return string The File name without extension.
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function name() {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->info == null) {
|
|
|
|
$this->info();
|
|
|
|
}
|
|
|
|
if (isset($this->info['extension'])) {
|
|
|
|
return basename($this->name, '.'.$this->info['extension']);
|
|
|
|
} elseif ($this->name) {
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* makes filename safe for saving
|
|
|
|
*
|
2010-01-25 16:01:05 +00:00
|
|
|
* @param string $name The name of the file to make safe if different from $this->name
|
|
|
|
* @param strin $ext The name of the extension to make safe if different from $this->ext
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string $ext the extension of the file
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function safe($name = null, $ext = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (!$name) {
|
|
|
|
$name = $this->name;
|
|
|
|
}
|
|
|
|
if (!$ext) {
|
|
|
|
$ext = $this->ext();
|
|
|
|
}
|
2008-09-12 05:11:34 +00:00
|
|
|
return preg_replace( "/(?:[^\w\.-]+)/", "_", basename($name, $ext));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Get md5 Checksum of file with previous check of Filesize
|
|
|
|
*
|
|
|
|
* @param mixed $maxsize in MB or true to force
|
|
|
|
* @return string md5 Checksum {@link http://php.net/md5_file See md5_file()}
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function md5($maxsize = 5) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($maxsize === true) {
|
2008-11-05 19:21:49 +00:00
|
|
|
return md5_file($this->path);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-06-04 21:29:26 +00:00
|
|
|
|
|
|
|
$size = $this->size();
|
|
|
|
if ($size && $size < ($maxsize * 1024) * 1024) {
|
|
|
|
return md5_file($this->path);
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-02-04 05:00:59 +00:00
|
|
|
* Returns the full path of the File.
|
2009-03-17 21:10:28 +00:00
|
|
|
*
|
2009-02-04 05:00:59 +00:00
|
|
|
* @return string Full path to file
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function pwd() {
|
2008-11-05 19:21:49 +00:00
|
|
|
if (is_null($this->path)) {
|
|
|
|
$this->path = $this->Folder->slashTerm($this->Folder->pwd()) . $this->name;
|
|
|
|
}
|
|
|
|
return $this->path;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the File exists.
|
|
|
|
*
|
|
|
|
* @return boolean true if it exists, false otherwise
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function exists() {
|
2008-11-05 19:21:49 +00:00
|
|
|
return (file_exists($this->path) && is_file($this->path));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns the "chmod" (permissions) of the File.
|
|
|
|
*
|
|
|
|
* @return string Permissions for the file
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function perms() {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->exists()) {
|
2008-11-05 19:21:49 +00:00
|
|
|
return substr(sprintf('%o', fileperms($this->path)), -4);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2008-11-03 18:20:57 +00:00
|
|
|
* Returns the Filesize
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2008-11-03 18:20:57 +00:00
|
|
|
* @return integer size of the file in bytes, or false in case of an error
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function size() {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->exists()) {
|
2008-11-05 19:21:49 +00:00
|
|
|
return filesize($this->path);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the File is writable.
|
|
|
|
*
|
|
|
|
* @return boolean true if its writable, false otherwise
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function writable() {
|
2008-11-05 19:21:49 +00:00
|
|
|
return is_writable($this->path);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the File is executable.
|
|
|
|
*
|
|
|
|
* @return boolean true if its executable, false otherwise
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function executable() {
|
2008-11-05 19:21:49 +00:00
|
|
|
return is_executable($this->path);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the File is readable.
|
|
|
|
*
|
|
|
|
* @return boolean true if file is readable, false otherwise
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function readable() {
|
2008-11-05 19:21:49 +00:00
|
|
|
return is_readable($this->path);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns the File's owner.
|
|
|
|
*
|
|
|
|
* @return integer the Fileowner
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function owner() {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->exists()) {
|
2008-11-05 19:21:49 +00:00
|
|
|
return fileowner($this->path);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return false;
|
2008-06-20 20:17:23 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-01-25 16:01:05 +00:00
|
|
|
* Returns the File's group.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @return integer the Filegroup
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function group() {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->exists()) {
|
2008-11-05 19:21:49 +00:00
|
|
|
return filegroup($this->path);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return false;
|
2008-06-20 20:17:23 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns last access time.
|
|
|
|
*
|
|
|
|
* @return integer timestamp Timestamp of last access time
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function lastAccess() {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->exists()) {
|
2008-11-05 19:21:49 +00:00
|
|
|
return fileatime($this->path);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return false;
|
2008-06-20 20:17:23 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns last modified time.
|
|
|
|
*
|
|
|
|
* @return integer timestamp Timestamp of last modification
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function lastChange() {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->exists()) {
|
2008-11-05 19:21:49 +00:00
|
|
|
return filemtime($this->path);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns the current folder.
|
|
|
|
*
|
|
|
|
* @return Folder Current folder
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function &Folder() {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $this->Folder;
|
|
|
|
}
|
2009-10-09 03:27:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy the File to $dest
|
|
|
|
*
|
|
|
|
* @param string $dest destination for the copy
|
|
|
|
* @param boolean $overwrite Overwrite $dest if exists
|
|
|
|
* @return boolean Succes
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function copy($dest, $overwrite = true) {
|
2009-10-09 03:27:31 +00:00
|
|
|
if (!$this->exists() || is_file($dest) && !$overwrite) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return copy($this->path, $dest);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|