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

Object

Package
cake
Subpackage
cake.cake.libs

Properties:

Show/Hide parent 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

append

top

Append 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

top

Used 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

top

Closes 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

top

Constructor

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

top

Copy 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

top

Creates the File.

Method defined in:
cake/libs/file.php on line 121
Return

boolean Success

Access

public

delete

top

Deletes the File.

Method defined in:
cake/libs/file.php on line 291
Return

boolean Success

Access

public

__destruct

top

Closes the current file if it is opened

Method defined in:
cake/libs/file.php on line 111

dispatchMethod

top

Calls 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

top

Returns 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

top

Returns 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

top

Returns the File extension.

Method defined in:
cake/libs/file.php on line 321
Return

string The File extension

Access

public

Folder

top

Returns the current folder.

Method defined in:
cake/libs/file.php on line 524
Return

Folder Current folder

Access

public

group

top

Returns the File's group.

Method defined in:
cake/libs/file.php on line 485
Return

integer the Filegroup

Access

public

info

top

Returns the File info.

Method defined in:
cake/libs/file.php on line 305
Return

string The File extension

Access

public

lastAccess

top

Returns last access time.

Method defined in:
cake/libs/file.php on line 498
Return

integer timestamp Timestamp of last access time

Access

public

lastChange

top

Returns last modified time.

Method defined in:
cake/libs/file.php on line 511
Return

integer timestamp Timestamp of last modification

Access

public

log

top

Convience 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

top

Get 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

top

Returns 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

top

A 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

top

Sets 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

top

Opens 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

top

Returns the File's owner.

Method defined in:
cake/libs/file.php on line 472
Return

integer the Fileowner

Access

public

perms

top

Returns 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

top

Checks 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

top

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"

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

top

Returns 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

top

Return the contents of this File as a string.

Parameters:
  • string $bytes optional false

    where to start

  • string $mode optional 'rb'

    A fread compatible 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

top

Returns 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

top

Calls 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

top

makes 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

top

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 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

top

Allows 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

top

Returns 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

top

Stop 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

top

Object-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

top

Returns 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

top

Write 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