File Class Info:
- Class Declaration:
class File extends Object
- File name:
- cake/libs/file.php
- Description:
Convenience class for reading, writing and appending to files.
- Class Inheritance
- Package
- cake
- Subpackage
- cake.cake.libs
Properties:
-
Folder Folder
Folder object of the File
-
handle resource
Holds the file handler resource if the file is opened
-
info string
file info
-
lock boolean
enable locking for file reading and writing
-
name string
Filename
-
path mixed null
path property
Current file's absolute path
Method Summary:
- append( $data, $force = false )
- cakeError( $method, $messages = array ( ) )
- close( )
- __construct( $path, $create = false, $mode = 493 )
- copy( $dest, $overwrite = true )
- create( )
- delete( )
- __destruct( )
- dispatchMethod( $method, $params = array ( ) )
- executable( )
- exists( )
- ext( )
- Folder( )
- group( )
- info( )
- lastAccess( )
- lastChange( )
- log( $msg, $type = 2 )
- md5( $maxsize = 5 )
- name( )
- Object( )
- offset( $offset = false, $seek = 0 )
- open( $mode = 'r', $force = false )
- owner( )
- perms( )
- _persist( $name, $return, $object, $type = NULL )
- prepare( $data, $forceWindows = false )
- pwd( )
- read( $bytes = false, $mode = 'rb', $force = false )
- readable( )
- requestAction( $url, $extra = array ( ) )
- safe( $name = NULL, $ext = NULL )
- _savePersistent( $name, $object )
- _set( $properties = array ( ) )
- size( )
- _stop( $status = 0 )
- toString( )
- writable( )
- write( $data, $mode = 'w', $force = false )
append
topAppend given data string to this File.
- Parameters:
-
-
string $data required
Data to write
-
string $force optional false
force the file to open
-
- Method defined in:
- cake/libs/file.php on line 268
- Return
boolean Success
- Access
public
cakeError
topUsed to report user friendly errors. If there is a file app/error.php or app/app_error.php this file will be loaded error.php is the AppError class it should extend ErrorHandler class.
- Parameters:
-
-
string $method required
Method to be called in the error class (AppError or ErrorHandler classes)
-
array $messages optional array ( )
Message that is to be displayed by the error class
-
- Method defined in:
- cake/libs/object.php on line 187
- Return
error message
- Access
public
close
topCloses the current file if it is opened.
- Method defined in:
- cake/libs/file.php on line 278
- Return
boolean True if closing was successful or file was already closed, otherwise false
- Access
public
__construct
topConstructor
- Parameters:
-
-
string $path required
Path to file
-
boolean $create optional false
Create file if it does not exist (if true)
-
integer $mode optional 493
Mode to apply to the folder holding the file
-
- Method defined in:
- cake/libs/file.php on line 97
copy
topCopy the File to $dest
- Parameters:
-
-
string $dest required
destination for the copy
-
boolean $overwrite optional true
Overwrite $dest if exists
-
- Method defined in:
- cake/libs/file.php on line 536
- Return
boolean Succes
- Access
public
create
topCreates the File.
- Method defined in:
- cake/libs/file.php on line 121
- Return
boolean Success
- Access
public
delete
topDeletes the File.
- Method defined in:
- cake/libs/file.php on line 291
- Return
boolean Success
- Access
public
__destruct
topdispatchMethod
topCalls a method on this object with the given parameters. Provides an OO wrapper
for call_user_func_array
- Parameters:
-
-
string $method required
Name of the method to call
-
array $params optional array ( )
Parameter list to use when calling $method
-
- Method defined in:
- cake/libs/object.php on line 107
- Return
mixed Returns the result of the method call
- Access
public
executable
topReturns true if the File is executable.
- Method defined in:
- cake/libs/file.php on line 452
- Return
boolean true if its executable, false otherwise
- Access
public
exists
topReturns true if the File exists.
- Method defined in:
- cake/libs/file.php on line 406
- Return
boolean true if it exists, false otherwise
- Access
public
ext
topReturns the File extension.
- Method defined in:
- cake/libs/file.php on line 321
- Return
string The File extension
- Access
public
Folder
topReturns the current folder.
- Method defined in:
- cake/libs/file.php on line 524
- Return
Folder Current folder
- Access
public
group
topReturns the File's group.
- Method defined in:
- cake/libs/file.php on line 485
- Return
integer the Filegroup
- Access
public
info
topReturns the File info.
- Method defined in:
- cake/libs/file.php on line 305
- Return
string The File extension
- Access
public
lastAccess
topReturns last access time.
- Method defined in:
- cake/libs/file.php on line 498
- Return
integer timestamp Timestamp of last access time
- Access
public
lastChange
topReturns last modified time.
- Method defined in:
- cake/libs/file.php on line 511
- Return
integer timestamp Timestamp of last modification
- Access
public
log
topConvience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.
- Parameters:
-
-
string $msg required
Log message
-
integer $type optional 2
Error type constant. Defined in app/config/core.php.
-
- Method defined in:
- cake/libs/object.php on line 148
- Return
boolean Success of log write
- Access
public
md5
topGet md5 Checksum of file with previous check of Filesize
- Parameters:
-
-
mixed $maxsize optional 5
in MB or true to force
-
- Method defined in:
- cake/libs/file.php on line 374
- Return
string md5 Checksum {@link http://php.net/md5_file See md5_file()}
- Access
public
name
topReturns the File name without extension.
- Method defined in:
- cake/libs/file.php on line 337
- Return
string The File name without extension.
- Access
public
Object
topA hack to support __construct() on PHP 4 Hint: descendant classes have no PHP4 class_name() constructors, so this constructor gets called first and calls the top-layer __construct() which (if present) should call parent::__construct()
- Method defined in:
- cake/libs/object.php on line 43
- Return
Object
offset
topSets or gets the offset for the currently opened file.
- Parameters:
-
-
mixed $offset optional false
The $offset in bytes to seek. If set to false then the current offset is returned.
-
integer $seek optional 0
PHP Constant SEEK_SET | SEEK_CUR | SEEK_END determining what the $offset is relative to
-
- Method defined in:
- cake/libs/file.php on line 204
- Return
mixed True on success, false on failure (set mode), false on failure or integer offset on success (get mode)
- Access
public
open
topOpens the current file with a given $mode
- Parameters:
-
-
string $mode optional 'r'
A valid 'fopen' mode string (r|w|a ...)
-
boolean $force optional false
If true then the file will be re-opened even if its already opened, otherwise it won't
-
- Method defined in:
- cake/libs/file.php on line 141
- Return
boolean True on success, false on failure
- Access
public
owner
topReturns the File's owner.
- Method defined in:
- cake/libs/file.php on line 472
- Return
integer the Fileowner
- Access
public
perms
topReturns the "chmod" (permissions) of the File.
- Method defined in:
- cake/libs/file.php on line 416
- Return
string Permissions for the file
- Access
public
_persist
topChecks for a persistent class file, if found file is opened and true returned If file is not found a file is created and false returned If used in other locations of the model you should choose a unique name for the persistent file There are many uses for this method, see manual for examples
- Parameters:
-
-
string $name required
name of the class to persist
-
$return required
-
string $object required
the object to persist
-
$type optional NULL
-
- Method defined in:
- cake/libs/object.php on line 218
- Return
boolean Success
- Access
protected
- Todo
add examples to manual
prepare
topPrepares 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"
- Parameters:
-
-
string $data required
Data to prepare for writing.
-
$forceWindows optional false
-
- Method defined in:
- cake/libs/file.php on line 224
- Return
string The with converted line endings.
- Access
public
pwd
topReturns the full path of the File.
- Method defined in:
- cake/libs/file.php on line 393
- Return
string Full path to file
- Access
public
read
topReturn the contents of this File as a string.
- Parameters:
-
-
string $bytes optional false
where to start
-
string $mode optional 'rb'
A
freadcompatible mode. -
boolean $force optional false
If true then the file will be re-opened even if its already opened, otherwise it won't
-
- Method defined in:
- cake/libs/file.php on line 168
- Return
mixed string on success, false on failure
- Access
public
readable
topReturns true if the File is readable.
- Method defined in:
- cake/libs/file.php on line 462
- Return
boolean true if file is readable, false otherwise
- Access
public
requestAction
topCalls a controller's method from any location. Can be used to connect controllers together or tie plugins into a main application. requestAction can be used to return rendered views or fetch the return value from controller actions.
- Parameters:
-
-
mixed $url required
String or array-based url.
-
array $extra optional array ( )
if array includes the key "return" it sets the AutoRender to true.
-
- Method defined in:
- cake/libs/object.php on line 80
- Return
mixed Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
- Access
public
safe
topmakes filename safe for saving
- Parameters:
-
-
string $name optional NULL
The name of the file to make safe if different from $this->name
-
strin $ext optional NULL
The name of the extension to make safe if different from $this->ext
-
- Method defined in:
- cake/libs/file.php on line 357
- Return
string $ext the extension of the file
- Access
public
_savePersistent
topYou should choose a unique name for the persistent file
There are many uses for this method, see manual for examples
- Parameters:
-
-
string $name required
name used for object to cache
-
object $object required
the object to persist
-
- Method defined in:
- cake/libs/object.php on line 247
- Return
boolean true on save, throws error if file can not be created
- Access
protected
_set
topAllows setting of multiple properties of the object in a single line of code. Will only set properties that are part of a class declaration.
- Parameters:
-
-
array $properties optional array ( )
An associative array containing properties and corresponding values.
-
- Method defined in:
- cake/libs/object.php on line 166
- Return
void
- Access
protected
size
topReturns the Filesize
- Method defined in:
- cake/libs/file.php on line 429
- Return
integer size of the file in bytes, or false in case of an error
- Access
public
_stop
topStop execution of the current script. Wraps exit() making testing easier.
- Parameters:
-
-
$status optional 0
-
- Method defined in:
- cake/libs/object.php on line 135
- Return
void
- Access
public
toString
topObject-to-string conversion. Each class can override this method as necessary.
- Method defined in:
- cake/libs/object.php on line 64
- Return
string The name of this class
- Access
public
writable
topReturns true if the File is writable.
- Method defined in:
- cake/libs/file.php on line 442
- Return
boolean true if its writable, false otherwise
- Access
public
write
topWrite given data to this File.
- Parameters:
-
-
string $data required
Data to write to this File.
-
string $mode optional 'w'
Mode of writing. {@link http://php.net/fwrite See fwrite()}.
-
string $force optional false
force the file to open
-
- Method defined in:
- cake/libs/file.php on line 241
- Return
boolean Success
- Access
public