File Class Info:

Class Declaration:

class File

File name:
Cake/Utility/File.php
Description:

Convenience class for reading, writing and appending to files.

Package
Cake.Utility

Properties:

  • Folder Folder

    Folder object of the File

  • handle resource

    Holds the file handler resource if the file is opened

    http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::$handle

  • info array

    File info

    http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::$info

  • lock boolean

    Enable locking for file reading and writing

    http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::$lock

  • name string

    Filename

    http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::$name

  • path mixed null

    Path property

    Current file's absolute path

    http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::$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/Utility/File.php on line 256

close

top

Closes the current file if it is opened.

Method defined in:
Cake/Utility/File.php on line 266
Return

boolean True if closing was successful or file was already closed, otherwise false

Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::close

__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/Utility/File.php on line 87

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/Utility/File.php on line 541

create

top

Creates the File.

Method defined in:
Cake/Utility/File.php on line 110

delete

top

Deletes the File.

Method defined in:
Cake/Utility/File.php on line 279

__destruct

top

Closes the current file if it is opened

Method defined in:
Cake/Utility/File.php on line 100

executable

top

Returns true if the File is executable.

Method defined in:
Cake/Utility/File.php on line 457
Return

boolean true if its executable, false otherwise

Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::executable

exists

top

Returns true if the File exists.

Method defined in:
Cake/Utility/File.php on line 411
Return

boolean true if it exists, false otherwise

Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::exists

ext

top

Returns the File extension.

Method defined in:
Cake/Utility/File.php on line 326

folder

top

Returns the current folder.

Method defined in:
Cake/Utility/File.php on line 529

group

top

Returns the File's group.

Method defined in:
Cake/Utility/File.php on line 490

info

top

Returns the File info as an array with the following keys:

  • dirname
  • basename
  • extension
  • filename
  • filesize
  • mime

Method defined in:
Cake/Utility/File.php on line 304

lastAccess

top

Returns last access time.

Method defined in:
Cake/Utility/File.php on line 503
Return

integer timestamp Timestamp of last access time

Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::lastAccess

lastChange

top

Returns last modified time.

Method defined in:
Cake/Utility/File.php on line 516
Return

integer timestamp Timestamp of last modification

Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::lastChange

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/Utility/File.php on line 379

mime

top

Get the mime type of the file. Uses the finfo extension if its available, otherwise falls back to mime_content_type

Method defined in:
Cake/Utility/File.php on line 554
Return

false|string The mimetype of the file, or false if reading fails.

name

top

Returns the File name without extension.

Method defined in:
Cake/Utility/File.php on line 342
Return

string The File name without extension.

Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::name

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/Utility/File.php on line 191
Return

mixed True on success, false on failure (set mode), false on failure or integer offset on success (get mode)

Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::offset

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/Utility/File.php on line 128
Return

boolean True on success, false on failure

Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::open

owner

top

Returns the File's owner.

Method defined in:
Cake/Utility/File.php on line 477

perms

top

Returns the "chmod" (permissions) of the File.

Method defined in:
Cake/Utility/File.php on line 421

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.

  • boolean $forceWindows optional false

    Data to prepare for writing.

Method defined in:
Cake/Utility/File.php on line 212

pwd

top

Returns the full path of the File.

Method defined in:
Cake/Utility/File.php on line 398

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/Utility/File.php on line 155
Return

mixed string on success, false on failure

Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::read

readable

top

Returns true if the File is readable.

Method defined in:
Cake/Utility/File.php on line 467
Return

boolean true if file is readable, false otherwise

Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::readable

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

  • string $ext optional NULL

    The name of the extension to make safe if different from $this->ext

Method defined in:
Cake/Utility/File.php on line 362

size

top

Returns the Filesize

Method defined in:
Cake/Utility/File.php on line 434
Return

integer size of the file in bytes, or false in case of an error

Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::size

writable

top

Returns true if the File is writable.

Method defined in:
Cake/Utility/File.php on line 447
Return

boolean true if its writable, false otherwise

Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::writable

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/Utility/File.php on line 229