cakephp2-php8/libs/file.php
phpnut 1dce095546 merging changes from sandboxes
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@856 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-09-17 02:22:07 +00:00

108 lines
No EOL
2.3 KiB
PHP

<?php
/* SVN FILE: $Id$ */
/**
* Convenience class for reading, writing and appending to files.
*
*
* 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.
*
* @filesource
* @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$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Convenience class for reading, writing and appending to files.
*
*
* @package cake
* @subpackage cake.libs
* @since CakePHP v 0.2.9
*/
class File
{
/**
* Path to file
*
* @var string
*/
var $path = null;
/**
* Constructor
*
* @param string $path
* @return File
*/
function File ($path)
{
$this->path = $path;
}
/**
* Return the contents of this File as a string.
*
* @return string Contents
*/
function read ()
{
return file_get_contents($this->path);
}
/**
* Append given data string to this File.
*
* @param string $data Data to write
* @return boolean Success
*/
function append ($data)
{
return $this->write($data, 'a');
}
/**
* Write given data to this File.
*
* @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
*/
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;
}
}
?>