2005-07-04 04:16:20 +00:00
|
|
|
<?php
|
2005-08-21 06:49:02 +00:00
|
|
|
/* SVN FILE: $Id$ */
|
2005-06-19 03:35:19 +00:00
|
|
|
|
2005-07-04 04:16:20 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Convenience class for reading, writing and appending to files.
|
2005-07-04 04:16:20 +00:00
|
|
|
*
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright (c) 2005, CakePHP Authors/Developers
|
|
|
|
*
|
|
|
|
* Author(s): Michal Tatarynowicz aka Pies <tatarynowicz@gmail.com>
|
|
|
|
* Larry E. Masters aka PhpNut <nut@phpnut.com>
|
|
|
|
* Kamil Dzielinski aka Brego <brego.dk@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2005-07-04 04:16:20 +00:00
|
|
|
* @filesource
|
2005-08-21 06:49:02 +00:00
|
|
|
* @author CakePHP Authors/Developers
|
|
|
|
* @copyright Copyright (c) 2005, CakePHP Authors/Developers
|
|
|
|
* @link https://trac.cakephp.org/wiki/Authors Authors/Developers
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.libs
|
|
|
|
* @since CakePHP v 0.2.9
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
2005-07-10 05:08:19 +00:00
|
|
|
* @lastmodified $Date$
|
2005-08-21 06:49:02 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2005-07-04 04:16:20 +00:00
|
|
|
*/
|
|
|
|
|
2005-08-21 06:49:02 +00:00
|
|
|
|
2005-07-04 04:16:20 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Convenience class for reading, writing and appending to files.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-07-04 04:16:20 +00:00
|
|
|
*
|
2005-08-21 06:49:02 +00:00
|
|
|
* @package cake
|
2005-07-04 04:16:20 +00:00
|
|
|
* @subpackage cake.libs
|
2005-08-21 06:49:02 +00:00
|
|
|
* @since CakePHP v 0.2.9
|
2005-07-04 04:16:20 +00:00
|
|
|
*/
|
2005-06-19 03:35:19 +00:00
|
|
|
class File
|
|
|
|
{
|
2005-07-04 04:16:20 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Path to file
|
2005-07-04 04:16:20 +00:00
|
|
|
*
|
2005-09-17 02:22:07 +00:00
|
|
|
* @var string
|
2005-07-04 04:16:20 +00:00
|
|
|
*/
|
2005-07-10 05:08:19 +00:00
|
|
|
var $path = null;
|
|
|
|
|
2005-07-04 04:16:20 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Constructor
|
2005-07-04 04:16:20 +00:00
|
|
|
*
|
2005-09-17 02:22:07 +00:00
|
|
|
* @param string $path
|
2005-07-04 04:16:20 +00:00
|
|
|
* @return File
|
|
|
|
*/
|
2005-07-10 05:08:19 +00:00
|
|
|
function File ($path)
|
|
|
|
{
|
|
|
|
$this->path = $path;
|
|
|
|
}
|
|
|
|
|
2005-07-04 04:16:20 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Return the contents of this File as a string.
|
2005-07-04 04:16:20 +00:00
|
|
|
*
|
2005-09-17 02:22:07 +00:00
|
|
|
* @return string Contents
|
2005-07-04 04:16:20 +00:00
|
|
|
*/
|
2005-07-10 05:08:19 +00:00
|
|
|
function read ()
|
|
|
|
{
|
|
|
|
return file_get_contents($this->path);
|
|
|
|
}
|
|
|
|
|
2005-07-04 04:16:20 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Append given data string to this File.
|
2005-07-04 04:16:20 +00:00
|
|
|
*
|
2005-09-17 02:22:07 +00:00
|
|
|
* @param string $data Data to write
|
|
|
|
* @return boolean Success
|
2005-07-04 04:16:20 +00:00
|
|
|
*/
|
2005-07-10 05:08:19 +00:00
|
|
|
function append ($data)
|
|
|
|
{
|
|
|
|
return $this->write($data, 'a');
|
|
|
|
}
|
|
|
|
|
2005-07-04 04:16:20 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Write given data to this File.
|
2005-07-04 04:16:20 +00:00
|
|
|
*
|
2005-09-17 02:22:07 +00:00
|
|
|
* @param string $data Data to write to this File.
|
|
|
|
* @param string $mode Mode of writing. {@link http://php.net/fwrite See fwrite()}.
|
|
|
|
* @return boolean Success
|
2005-07-04 04:16:20 +00:00
|
|
|
*/
|
2005-07-10 05:08:19 +00:00
|
|
|
function write ($data, $mode = 'w')
|
|
|
|
{
|
|
|
|
if (!($handle = fopen($this->path, $mode)))
|
|
|
|
{
|
|
|
|
print ("[File] Could not open {$this->path} with mode $mode!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fwrite($handle, $data))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!fclose($handle))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2005-06-19 03:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|