2005-10-03 04:48:00 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
|
|
|
* Convenience class for reading, writing and appending to files.
|
2005-12-27 03:33:44 +00:00
|
|
|
*
|
2005-10-03 04:48:00 +00:00
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2007-02-02 10:39:45 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
2008-01-01 22:18:17 +00:00
|
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc.
|
2006-05-26 05:29:17 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2005-12-23 21:57:26 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2005-12-27 03:33:44 +00:00
|
|
|
* @filesource
|
2008-01-01 22:18:17 +00:00
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
|
2007-02-02 10:39:45 +00:00
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
2007-02-02 10:39:45 +00:00
|
|
|
* @since CakePHP(tm) v 0.2.9
|
2006-05-26 05:29:17 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Included libraries.
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
|
|
|
*/
|
2007-10-16 09:48:59 +00:00
|
|
|
if (!class_exists('Object')) {
|
|
|
|
uses ('object');
|
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
|
2007-10-16 09:48:59 +00:00
|
|
|
if (!class_exists('Folder')) {
|
|
|
|
uses ('folder');
|
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
|
|
|
* Convenience class for reading, writing and appending to files.
|
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2007-10-16 09:48:59 +00:00
|
|
|
class File extends Object {
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2007-05-03 23:22:02 +00:00
|
|
|
* Folder object of the File
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2007-05-22 02:38:12 +00:00
|
|
|
* @var object
|
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2007-05-03 23:22:02 +00:00
|
|
|
var $Folder = null;
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
|
|
|
* Filename
|
|
|
|
*
|
|
|
|
* @var string
|
2007-05-22 02:38:12 +00:00
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $name = null;
|
2007-05-30 00:09:14 +00:00
|
|
|
/**
|
|
|
|
* file info
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2007-08-05 16:47:03 +00:00
|
|
|
var $info = array();
|
2007-10-09 00:00:46 +00:00
|
|
|
/**
|
|
|
|
* Holds the file handler resource if the file is opened
|
|
|
|
*
|
2007-10-09 00:04:44 +00:00
|
|
|
* @var resource
|
2007-10-09 00:00:46 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $handle = null;
|
2007-10-17 07:34:16 +00:00
|
|
|
/**
|
|
|
|
* enable locking for file reading and writing
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $lock = null;
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2007-05-20 06:30:19 +00:00
|
|
|
* @param string $path Path to file
|
2007-10-22 16:54:36 +00:00
|
|
|
* @param boolean $create Create file if it does not exist (if true)
|
2007-10-22 16:11:12 +00:00
|
|
|
* @param integer $mode Mode to apply to the folder holding the file
|
2007-10-16 09:48:59 +00:00
|
|
|
* @access private
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2007-05-14 12:23:25 +00:00
|
|
|
function __construct($path, $create = false, $mode = 0755) {
|
2006-05-26 05:29:17 +00:00
|
|
|
parent::__construct();
|
2007-05-27 00:30:43 +00:00
|
|
|
$this->Folder =& new Folder(dirname($path), $create, $mode);
|
2007-09-20 02:54:20 +00:00
|
|
|
if (!is_dir($path)) {
|
|
|
|
$this->name = basename($path);
|
|
|
|
}
|
2008-05-18 14:48:48 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if (!$this->exists()) {
|
|
|
|
if ($create === true) {
|
2007-10-16 09:48:59 +00:00
|
|
|
if ($this->safe($path) && $this->create() === false) {
|
2006-05-26 05:29:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-09 00:00:46 +00:00
|
|
|
/**
|
|
|
|
* Closes the current file if it is opened
|
|
|
|
*
|
2007-10-16 09:48:59 +00:00
|
|
|
* @access private
|
2007-10-09 00:00:46 +00:00
|
|
|
*/
|
|
|
|
function __destruct() {
|
|
|
|
$this->close();
|
|
|
|
}
|
2007-10-16 09:48:59 +00:00
|
|
|
/**
|
|
|
|
* Creates the File.
|
|
|
|
*
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean Success
|
2007-10-16 09:48:59 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function create() {
|
|
|
|
$dir = $this->Folder->pwd();
|
|
|
|
if (is_dir($dir) && is_writable($dir) && !$this->exists()) {
|
|
|
|
if (touch($this->pwd())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-09 00:00:46 +00:00
|
|
|
/**
|
|
|
|
* Opens the current file with a given $mode
|
|
|
|
*
|
|
|
|
* @param string $mode A valid 'fopen' mode string (r|w|a ...)
|
2007-10-22 16:54:36 +00:00
|
|
|
* @param boolean $force If true then the file will be re-opened even if its already opened, otherwise it won't
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean True on success, false on failure
|
2007-10-09 00:00:46 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function open($mode = 'r', $force = false) {
|
2007-10-16 09:48:59 +00:00
|
|
|
if (!$force && is_resource($this->handle)) {
|
2007-10-09 00:00:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2007-10-16 09:48:59 +00:00
|
|
|
if ($this->exists() === false) {
|
|
|
|
if ($this->create() === false) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-09 00:00:46 +00:00
|
|
|
}
|
2008-05-18 14:48:48 +00:00
|
|
|
|
2007-10-16 09:48:59 +00:00
|
|
|
$this->handle = fopen($this->pwd(), $mode);
|
|
|
|
if (is_resource($this->handle)) {
|
2007-10-09 00:00:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2007-10-16 09:48:59 +00:00
|
|
|
return false;
|
2007-10-09 00:00:46 +00:00
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
|
|
|
* Return the contents of this File as a string.
|
|
|
|
*
|
2007-10-16 09:48:59 +00:00
|
|
|
* @param string $bytes where to start
|
|
|
|
* @param string $mode
|
2007-10-22 16:54:36 +00:00
|
|
|
* @param boolean $force If true then the file will be re-opened even if its already opened, otherwise it won't
|
2007-10-16 09:48:59 +00:00
|
|
|
* @return mixed string on success, false on failure
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2007-10-16 09:48:59 +00:00
|
|
|
function read($bytes = false, $mode = 'rb', $force = false) {
|
2007-10-17 07:34:16 +00:00
|
|
|
$success = false;
|
|
|
|
if ($this->lock !== null) {
|
|
|
|
if (flock($this->handle, LOCK_SH) === false) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-16 09:48:59 +00:00
|
|
|
}
|
2007-10-17 07:34:16 +00:00
|
|
|
if ($bytes === false) {
|
|
|
|
$success = file_get_contents($this->pwd());
|
2007-10-22 00:26:54 +00:00
|
|
|
} elseif ($this->open($mode, $force) === true) {
|
2007-10-16 09:48:59 +00:00
|
|
|
if (is_int($bytes)) {
|
2007-10-22 00:26:54 +00:00
|
|
|
$success = fread($this->handle, $bytes);
|
2007-10-16 09:48:59 +00:00
|
|
|
} else {
|
|
|
|
$data = '';
|
|
|
|
while (!feof($this->handle)) {
|
|
|
|
$data .= fgets($this->handle, 4096);
|
|
|
|
}
|
2007-10-17 07:34:16 +00:00
|
|
|
$success = trim($data);
|
2007-10-16 09:48:59 +00:00
|
|
|
}
|
2007-10-09 00:00:46 +00:00
|
|
|
}
|
2007-10-17 07:34:16 +00:00
|
|
|
if ($this->lock !== null) {
|
|
|
|
flock($this->handle, LOCK_UN);
|
|
|
|
}
|
|
|
|
return $success;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-10-11 07:49:57 +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.
|
2007-10-22 16:11:12 +00:00
|
|
|
* @param integer $seek PHP Constant SEEK_SET | SEEK_CUR | SEEK_END determining what the $offset is relative to
|
2007-10-11 07:49:57 +00:00
|
|
|
* @return mixed True on success, false on failure (set mode), false on failure or integer offset on success (get mode)
|
|
|
|
* @access public
|
|
|
|
*/
|
2007-10-16 09:48:59 +00:00
|
|
|
function offset($offset = false, $seek = SEEK_SET) {
|
2007-10-11 07:49:57 +00:00
|
|
|
if ($offset === false) {
|
2007-10-16 09:48:59 +00:00
|
|
|
if (is_resource($this->handle)) {
|
|
|
|
return ftell($this->handle);
|
2007-10-11 07:49:57 +00:00
|
|
|
}
|
2007-10-16 09:48:59 +00:00
|
|
|
} elseif ($this->open() === true) {
|
|
|
|
return fseek($this->handle, $offset, $seek) === 0;
|
2007-10-11 07:49:57 +00:00
|
|
|
}
|
2007-10-16 09:48:59 +00:00
|
|
|
return false;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-10-25 03:10:31 +00:00
|
|
|
/**
|
|
|
|
* Prepares a ascii string for writing
|
|
|
|
* fixes line endings
|
|
|
|
*
|
|
|
|
* @param string $data Data to prepare for writing.
|
|
|
|
* @return string
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-18 14:48:48 +00:00
|
|
|
function prepare($data, $forceWindows = false) {
|
2007-10-25 03:10:31 +00:00
|
|
|
$lineBreak = "\n";
|
2008-05-18 14:48:48 +00:00
|
|
|
if (substr(PHP_OS,0,3) == "WIN" || $forceWindows === true) {
|
2007-10-25 03:10:31 +00:00
|
|
|
$lineBreak = "\r\n";
|
2008-05-23 05:11:41 +00:00
|
|
|
}
|
|
|
|
return strtr($data, array("\r\n" => $lineBreak, "\n" => $lineBreak, "\r" => $lineBreak));
|
2007-10-25 03:10:31 +00:00
|
|
|
}
|
|
|
|
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2005-12-27 03:33:44 +00:00
|
|
|
* Write given data to this File.
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @param string $data Data to write to this File.
|
|
|
|
* @param string $mode Mode of writing. {@link http://php.net/fwrite See fwrite()}.
|
2007-10-16 09:48:59 +00:00
|
|
|
* @param string $force force the file to open
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean Success
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2007-10-16 09:48:59 +00:00
|
|
|
function write($data, $mode = 'w', $force = false) {
|
2007-10-17 07:34:16 +00:00
|
|
|
$success = false;
|
2007-10-16 09:48:59 +00:00
|
|
|
if ($this->open($mode, $force) === true) {
|
2007-10-17 07:34:16 +00:00
|
|
|
if($this->lock !== null) {
|
|
|
|
if(flock($this->handle, LOCK_EX) === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2007-10-22 04:44:39 +00:00
|
|
|
|
2007-10-16 09:48:59 +00:00
|
|
|
if (fwrite($this->handle, $data) !== false) {
|
2007-10-17 07:34:16 +00:00
|
|
|
$success = true;
|
|
|
|
}
|
2008-05-18 14:48:48 +00:00
|
|
|
if ($this->lock !== null) {
|
2007-10-17 07:34:16 +00:00
|
|
|
flock($this->handle, LOCK_UN);
|
2007-10-16 09:48:59 +00:00
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-10-17 07:34:16 +00:00
|
|
|
return $success;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-05-27 00:30:43 +00:00
|
|
|
/**
|
2007-10-16 09:48:59 +00:00
|
|
|
* Append given data string to this File.
|
2007-05-27 00:30:43 +00:00
|
|
|
*
|
2007-10-16 09:48:59 +00:00
|
|
|
* @param string $data Data to write
|
|
|
|
* @param string $force force the file to open
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean Success
|
2007-05-27 00:30:43 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2007-10-16 09:48:59 +00:00
|
|
|
function append($data, $force = false) {
|
|
|
|
return $this->write($data, 'a', $force);
|
2007-05-27 00:30:43 +00:00
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2007-10-16 09:48:59 +00:00
|
|
|
* Closes the current file if it is opened.
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean True if closing was successful or file was already closed, otherwise false
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2007-10-16 09:48:59 +00:00
|
|
|
function close() {
|
|
|
|
if (!is_resource($this->handle)) {
|
|
|
|
return true;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-10-16 09:48:59 +00:00
|
|
|
return fclose($this->handle);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2007-10-16 09:48:59 +00:00
|
|
|
* Deletes the File.
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean Success
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2007-10-16 09:48:59 +00:00
|
|
|
function delete() {
|
|
|
|
if ($this->exists()) {
|
|
|
|
return unlink($this->pwd());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2007-05-27 16:06:49 +00:00
|
|
|
/**
|
|
|
|
* Returns the File extension.
|
|
|
|
*
|
|
|
|
* @return string The File extension
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function info() {
|
2007-06-20 06:15:35 +00:00
|
|
|
if ($this->info == null) {
|
2007-05-30 00:09:14 +00:00
|
|
|
$this->info = pathinfo($this->pwd());
|
|
|
|
}
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!isset($this->info['filename'])) {
|
2007-08-21 03:39:02 +00:00
|
|
|
$this->info['filename'] = $this->name();
|
2007-05-29 23:38:36 +00:00
|
|
|
}
|
2007-05-30 00:09:14 +00:00
|
|
|
return $this->info;
|
2007-05-29 23:38:36 +00:00
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Returns the File extension.
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2007-05-20 06:30:19 +00:00
|
|
|
* @return string The File extension
|
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2007-05-27 00:30:43 +00:00
|
|
|
function ext() {
|
2007-06-20 06:15:35 +00:00
|
|
|
if ($this->info == null) {
|
2007-05-30 00:09:14 +00:00
|
|
|
$this->info();
|
|
|
|
}
|
2007-06-20 06:15:35 +00:00
|
|
|
if (isset($this->info['extension'])) {
|
2007-05-30 00:09:14 +00:00
|
|
|
return $this->info['extension'];
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-05-27 16:06:49 +00:00
|
|
|
return false;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-05-27 16:06:49 +00:00
|
|
|
/**
|
|
|
|
* Returns the File name without extension.
|
|
|
|
*
|
|
|
|
* @return string The File name without extension.
|
|
|
|
* @access public
|
|
|
|
*/
|
2007-08-21 03:39:02 +00:00
|
|
|
function name() {
|
2007-06-20 06:15:35 +00:00
|
|
|
if ($this->info == null) {
|
2007-05-30 00:09:14 +00:00
|
|
|
$this->info();
|
|
|
|
}
|
2007-06-20 06:15:35 +00:00
|
|
|
if (isset($this->info['extension'])) {
|
2007-05-30 00:09:14 +00:00
|
|
|
return basename($this->name, '.'.$this->info['extension']);
|
2007-09-20 02:54:20 +00:00
|
|
|
} elseif ($this->name) {
|
|
|
|
return $this->name;
|
2007-05-27 16:06:49 +00:00
|
|
|
}
|
|
|
|
return false;
|
2007-05-29 23:38:36 +00:00
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2007-10-16 09:48:59 +00:00
|
|
|
* makes filename safe for saving
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2007-10-16 09:48:59 +00:00
|
|
|
* @param string $name the name of the file to make safe if different from $this->name
|
|
|
|
* @return string $ext the extension of the file
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2007-10-16 09:48:59 +00:00
|
|
|
function safe($name = null, $ext = null) {
|
|
|
|
if (!$name) {
|
|
|
|
$name = $this->name;
|
|
|
|
}
|
|
|
|
if (!$ext) {
|
|
|
|
$ext = $this->ext();
|
|
|
|
}
|
|
|
|
return preg_replace( "/[^\w\.-]+/", "_", basename($name, $ext));
|
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2007-10-16 09:48:59 +00:00
|
|
|
* Get md5 Checksum of file with previous check of Filesize
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2007-10-16 09:48:59 +00:00
|
|
|
* @param mixed $maxsize in MB or true to force
|
|
|
|
* @return string md5 Checksum {@link http://php.net/md5_file See md5_file()}
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2007-10-16 09:48:59 +00:00
|
|
|
function md5($maxsize = 5) {
|
|
|
|
if ($maxsize === true) {
|
|
|
|
return md5_file($this->pwd());
|
2006-05-26 05:29:17 +00:00
|
|
|
} else {
|
2007-10-16 09:48:59 +00:00
|
|
|
$size = $this->size();
|
|
|
|
if ($size && $size < ($maxsize * 1024) * 1024) {
|
|
|
|
return md5_file($this->pwd());
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-10-16 09:48:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Returns the full path of the File.
|
|
|
|
*
|
|
|
|
* @return string Full path to file
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function pwd() {
|
|
|
|
return $this->Folder->slashTerm($this->Folder->pwd()) . $this->name;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Returns true if the File exists.
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean true if it exists, false otherwise
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function exists() {
|
2007-05-27 00:30:43 +00:00
|
|
|
$exists = (file_exists($this->pwd()) && is_file($this->pwd()));
|
2006-05-26 05:29:17 +00:00
|
|
|
return $exists;
|
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2007-10-16 09:48:59 +00:00
|
|
|
* Returns the "chmod" (permissions) of the File.
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2007-10-16 09:48:59 +00:00
|
|
|
* @return string Permissions for the file
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2007-10-16 09:48:59 +00:00
|
|
|
function perms() {
|
|
|
|
if ($this->exists()) {
|
|
|
|
return substr(sprintf('%o', fileperms($this->pwd())), -4);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Returns the Filesize, either in bytes or in human-readable format.
|
|
|
|
*
|
2007-10-22 16:54:36 +00:00
|
|
|
* @param boolean $humanReadeble Data to write to this File.
|
2007-10-16 09:48:59 +00:00
|
|
|
* @return string|int filesize as int or as a human-readable string
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function size() {
|
|
|
|
if ($this->exists()) {
|
|
|
|
return filesize($this->pwd());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Returns true if the File is writable.
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean true if its writable, false otherwise
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function writable() {
|
2007-10-16 09:48:59 +00:00
|
|
|
return is_writable($this->pwd());
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Returns true if the File is executable.
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean true if its executable, false otherwise
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function executable() {
|
2007-10-16 09:48:59 +00:00
|
|
|
return is_executable($this->pwd());
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-10-09 00:00:46 +00:00
|
|
|
/**
|
2007-10-16 09:48:59 +00:00
|
|
|
* Returns true if the File is readable.
|
2007-10-09 00:00:46 +00:00
|
|
|
*
|
2007-10-22 16:09:35 +00:00
|
|
|
* @return boolean true if file is readable, false otherwise
|
2007-10-09 00:00:46 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2007-10-16 09:48:59 +00:00
|
|
|
function readable() {
|
|
|
|
return is_readable($this->pwd());
|
2007-10-09 00:00:46 +00:00
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2007-10-16 09:48:59 +00:00
|
|
|
* Returns the File's owner.
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2007-10-22 16:54:36 +00:00
|
|
|
* @return integer the Fileowner
|
2007-10-16 09:48:59 +00:00
|
|
|
*/
|
|
|
|
function owner() {
|
|
|
|
if ($this->exists()) {
|
|
|
|
return fileowner($this->pwd());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Returns the File group.
|
|
|
|
*
|
2007-10-22 16:54:36 +00:00
|
|
|
* @return integer the Filegroup
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2007-10-16 09:48:59 +00:00
|
|
|
function group() {
|
|
|
|
if ($this->exists()) {
|
|
|
|
return filegroup($this->pwd());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Returns last access time.
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2007-10-22 16:54:36 +00:00
|
|
|
* @return integer timestamp Timestamp of last access time
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function lastAccess() {
|
2007-10-16 09:48:59 +00:00
|
|
|
if ($this->exists()) {
|
|
|
|
return fileatime($this->pwd());
|
|
|
|
}
|
|
|
|
return false;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Returns last modified time.
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2007-10-22 16:54:36 +00:00
|
|
|
* @return integer timestamp Timestamp of last modification
|
2007-05-20 06:30:19 +00:00
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function lastChange() {
|
2007-10-16 09:48:59 +00:00
|
|
|
if ($this->exists()) {
|
|
|
|
return filemtime($this->pwd());
|
|
|
|
}
|
|
|
|
return false;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Returns the current folder.
|
2005-10-03 04:48:00 +00:00
|
|
|
*
|
2007-05-20 06:30:19 +00:00
|
|
|
* @return Folder Current folder
|
|
|
|
* @access public
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2007-05-27 00:30:43 +00:00
|
|
|
function &Folder() {
|
2007-05-03 23:22:02 +00:00
|
|
|
return $this->Folder;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-05-27 00:30:43 +00:00
|
|
|
/* Deprecated methods */
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* @see File::pwd
|
2005-10-03 04:48:00 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function getFullPath() {
|
2007-08-21 03:39:02 +00:00
|
|
|
trigger_error('Deprecated: Use File::pwd() instead.', E_USER_WARNING);
|
2007-05-27 00:30:43 +00:00
|
|
|
return $this->pwd();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* @see File::name
|
|
|
|
*/
|
|
|
|
function getName() {
|
2007-08-21 03:39:02 +00:00
|
|
|
trigger_error('Deprecated: Use File::name() instead.', E_USER_WARNING);
|
2007-05-27 00:30:43 +00:00
|
|
|
return $this->name;
|
|
|
|
}
|
2007-08-21 03:39:02 +00:00
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* @see File::name()
|
|
|
|
*/
|
|
|
|
function filename() {
|
|
|
|
trigger_error('Deprecated: Use File::name() instead.', E_USER_WARNING);
|
|
|
|
return $this->name();
|
|
|
|
}
|
2007-05-27 00:30:43 +00:00
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* @see File::ext()
|
|
|
|
*/
|
|
|
|
function getExt() {
|
2007-08-21 03:39:02 +00:00
|
|
|
trigger_error('Deprecated: Use File::ext() instead.', E_USER_WARNING);
|
2007-05-27 00:30:43 +00:00
|
|
|
return $this->ext();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @deprecated
|
2007-08-21 03:39:02 +00:00
|
|
|
* @see File::md5()
|
2007-05-27 00:30:43 +00:00
|
|
|
*/
|
|
|
|
function getMd5() {
|
2007-08-21 03:39:02 +00:00
|
|
|
trigger_error('Deprecated: Use File::md5() instead.', E_USER_WARNING);
|
2007-05-27 00:30:43 +00:00
|
|
|
return $this->md5();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* @see File::size()
|
|
|
|
*/
|
|
|
|
function getSize() {
|
2007-08-21 03:39:02 +00:00
|
|
|
trigger_error('Deprecated: Use File::size() instead.', E_USER_WARNING);
|
2007-05-27 00:30:43 +00:00
|
|
|
return $this->size();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* @see File::owner()
|
|
|
|
*/
|
|
|
|
function getOwner() {
|
2007-08-21 03:39:02 +00:00
|
|
|
trigger_error('Deprecated: Use File::owner() instead.', E_USER_WARNING);
|
2007-05-27 00:30:43 +00:00
|
|
|
return $this->owner();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* @see File::group()
|
|
|
|
*/
|
|
|
|
function getGroup() {
|
2007-08-21 03:39:02 +00:00
|
|
|
trigger_error('Deprecated: Use File::group() instead.', E_USER_WARNING);
|
2007-05-27 00:30:43 +00:00
|
|
|
return $this->group();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* @see File::perms()
|
|
|
|
*/
|
|
|
|
function getChmod() {
|
2007-08-21 03:39:02 +00:00
|
|
|
trigger_error('Deprecated: Use File::perms() instead.', E_USER_WARNING);
|
2007-05-27 00:30:43 +00:00
|
|
|
return $this->perms();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* @see File::Folder()
|
|
|
|
*/
|
|
|
|
function getFolder() {
|
2007-08-21 03:39:02 +00:00
|
|
|
trigger_error('Deprecated: Use File::Folder() instead.', E_USER_WARNING);
|
2007-05-27 00:30:43 +00:00
|
|
|
return $this->Folder();
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-10-03 04:48:00 +00:00
|
|
|
}
|
2005-12-27 03:33:44 +00:00
|
|
|
?>
|