Class File
Convenience class for reading, writing and appending to files.
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Located at Cake/Utility/File.php
Method Detail
__constructsource public
__construct( string $path , boolean $create false , integer $mode 0755 )
Constructor
Parameters
-  string 
$path - Path to file
 -  boolean 
$createoptional false - Create file if it does not exist (if true)
 -  integer 
$modeoptional 0755 - Mode to apply to the folder holding the file
 
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Fileappendsource public
append( string $data , string $force false )
Append given data string to this file.
Parameters
-  string 
$data - Data to write
 -  string 
$forceoptional false - Force the file to open
 
Returns
booleanSuccess
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::appendclearStatCachesource 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 
$alloptional false - Clear all cache or not
 
closesource public
close( )
Closes the current file if it is opened.
Returns
booleanTrue 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::closecopysource public
copy( string $dest , boolean $overwrite true )
Copy the File to $dest
Parameters
-  string 
$dest - Destination for the copy
 -  boolean 
$overwriteoptional true - Overwrite $dest if exists
 
Returns
booleanSuccess
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::copycreatesource public
create( )
Creates the file.
Returns
booleanSuccess
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::createdeletesource public
delete( )
Deletes the file.
Returns
booleanSuccess
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::deleteexecutablesource public
executable( )
Returns true if the File is executable.
Returns
booleanTrue if it's executable, false otherwise
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::executableexistssource public
exists( )
Returns true if the file exists.
Returns
booleanTrue if it exists, false otherwise
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::existsextsource public
ext( )
Returns the file extension.
Returns
stringThe file extension
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::extfoldersource public
folder( )
Returns the current folder.
Returns
FolderCurrent folder
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::Foldergroupsource public
group( )
Returns the file's group.
Returns
integer|falseThe file group, or false in case of an error
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::groupinfosource public
info( )
Returns the file info as an array with the following keys:
- dirname
 - basename
 - extension
 - filename
 - filesize
 - mime
 
Returns
arrayFile information.
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::infolastAccesssource public
lastAccess( )
Returns last access time.
Returns
integer|falseTimestamp of last access time, or false in case of an error
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::lastAccesslastChangesource public
lastChange( )
Returns last modified time.
Returns
integer|falseTimestamp 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::lastChangemd5source public
md5( integer|boolean $maxsize 5 )
Get md5 Checksum of file with previous check of Filesize
Parameters
-  integer|boolean 
$maxsizeoptional 5 - in MB or true to force
 
Returns
string|falsemd5 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::md5mimesource 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|stringThe mimetype of the file, or false if reading fails.
namesource public
name( )
Returns the file name without extension.
Returns
stringThe file name without extension.
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::nameoffsetsource public
offset( integer|boolean $offset false , integer $seek SEEK_SET )
Sets or gets the offset for the currently opened file.
Parameters
-  integer|boolean 
$offsetoptional false - The $offset in bytes to seek. If set to false then the current offset is returned.
 -  integer 
$seekoptional SEEK_SET - PHP Constant SEEK_SET | SEEK_CUR | SEEK_END determining what the $offset is relative to
 
Returns
mixedTrue 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::offsetopensource public
open( string $mode 'r' , boolean $force false )
Opens the current file with a given $mode
Parameters
-  string 
$modeoptional 'r' - A valid 'fopen' mode string (r|w|a ...)
 -  boolean 
$forceoptional false - If true then the file will be re-opened even if its already opened, otherwise it won't
 
Returns
booleanTrue on success, false on failure
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::openownersource public
owner( )
Returns the file's owner.
Returns
integer|falseThe file owner, or false in case of an error
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::ownerpermssource public
perms( )
Returns the "chmod" (permissions) of the file.
Returns
string|falsePermissions 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::permspreparesource 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 
$forceWindowsoptional false - If true forces usage Windows newline string.
 
Returns
stringThe with converted line endings.
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::preparepwdsource public
pwd( )
Returns the full path of the file.
Returns
stringFull path to the file
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::pwdreadsource public
read( string $bytes false , string $mode 'rb' , boolean $force false )
Return the contents of this file as a string.
Parameters
-  string 
$bytesoptional false - where to start
 -  string 
$modeoptional 'rb' - A 
freadcompatible mode. -  boolean 
$forceoptional false - If true then the file will be re-opened even if its already opened, otherwise it won't
 
Returns
mixedstring on success, false on failure
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::readreadablesource public
readable( )
Returns true if the file is readable.
Returns
booleanTrue if file is readable, false otherwise
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::readablereplaceTextsource 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
booleanSuccess
safesource public
safe( string $name null , string $ext null )
Makes file name safe for saving
Parameters
-  string 
$nameoptional null - The name of the file to make safe if different from $this->name
 -  string 
$extoptional null - The name of the extension to make safe if different from $this->ext
 
Returns
stringext The extension of the file
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::safesizesource public
size( )
Returns the file size
Returns
integer|falseSize 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::sizewritablesource public
writable( )
Returns true if the file is writable.
Returns
booleanTrue if it's writable, false otherwise
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::writablewritesource 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 
$modeoptional 'w' - Mode of writing. See fwrite().
 -  string 
$forceoptional false - Force the file to open
 
Returns
booleanSuccess
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::writeProperties summary
    © 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