Class File

Convenience class for reading, writing and appending to files.

Method Detail

__constructsource public

__construct( string $path , boolean $create false , integer $mode 0755 )

Constructor

Parameters

string $path
Path to file
boolean $create optional false
Create file if it does not exist (if true)
integer $mode optional 0755
Mode to apply to the folder holding the file

Link

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

__destructsource public

__destruct( )

Closes the current file if it is opened

appendsource public

append( string $data , string $force false )

Append given data string to this file.

Parameters

string $data
Data to write
string $force optional false
Force the file to open

Returns

boolean
Success

Link

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

clearStatCachesource public

clearStatCache( boolean $all false )

Clear PHP's internal stat cache

For 5.3 onwards it's possible to clear cache for just a single file. Passing true will clear all the stat cache.

Parameters

boolean $all optional false
Clear all cache or not

closesource public

close( )

Closes the current file if it is opened.

Returns

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

copysource public

copy( string $dest , boolean $overwrite true )

Copy the File to $dest

Parameters

string $dest
Destination for the copy
boolean $overwrite optional true
Overwrite $dest if exists

Returns

boolean
Success

Link

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

infosource public

info( )

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

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

Returns

array
File information.

Link

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

lastChangesource public

lastChange( )

Returns last modified time.

Returns

integer|false
Timestamp of last modification, or false in case of an error

Link

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

md5source public

md5( integer|boolean $maxsize 5 )

Get md5 Checksum of file with previous check of Filesize

Parameters

integer|boolean $maxsize optional 5
in MB or true to force

Returns

string|false
md5 Checksum See md5_file(), or false in case of an error

Link

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

mimesource public

mime( )

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

Returns

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

offsetsource public

offset( integer|boolean $offset false , integer $seek SEEK_SET )

Sets or gets the offset for the currently opened file.

Parameters

integer|boolean $offset optional false
The $offset in bytes to seek. If set to false then the current offset is returned.
integer $seek optional SEEK_SET
PHP Constant SEEK_SET | SEEK_CUR | SEEK_END determining what the $offset is relative to

Returns

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

opensource public

open( string $mode 'r' , boolean $force false )

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

Returns

boolean
True on success, false on failure

Link

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

permssource public

perms( )

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

Returns

string|false
Permissions for the file, or false in case of an error

Link

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

preparesource public static

prepare( string $data , boolean $forceWindows false )

Prepares an 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
Data to prepare for writing.
boolean $forceWindows optional false
If true forces usage Windows newline string.

Returns

string
The with converted line endings.

Link

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

readsource public

read( string $bytes false , string $mode 'rb' , boolean $force false )

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

Returns

mixed
string on success, false on failure

Link

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

replaceTextsource public

replaceText( string|array $search , string|array $replace )

Searches for a given text and replaces the text if found.

Parameters

string|array $search
Text(s) to search for.
string|array $replace
Text(s) to replace with.

Returns

boolean
Success

safesource public

safe( string $name null , string $ext null )

Makes file name 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

Returns

string
ext The extension of the file

Link

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

writesource public

write( string $data , string $mode 'w' , string $force false )

Write given data to this file.

Parameters

string $data
Data to write to this File.
string $mode optional 'w'
Mode of writing. See fwrite().
string $force optional false
Force the file to open

Returns

boolean
Success

Link

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

Properties summary

$handlesource

public resource

Holds the file handler resource if the file is opened

null

$infosource

public array

File info

array()

$locksource

public boolean

Enable locking for file reading and writing

null

$namesource

public string

File name

null

$pathsource

public mixed

Path property

Current file's absolute path

null

© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/2.7/class-File.html