CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.2 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.2
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • CakeNumber
  • CakeTime
  • ClassRegistry
  • Debugger
  • File
  • Folder
  • Hash
  • Inflector
  • ObjectCollection
  • Sanitize
  • Security
  • Set
  • String
  • Validation
  • Xml

Class File

Convenience class for reading, writing and appending to files.

Package: Cake\Utility
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: Cake/Utility/File.php

Properties summary

  • $Folder public
    Folder
    Folder object of the File
  • $handle public
    resource
    Holds the file handler resource if the file is opened
  • $info public
    array
    File info
  • $lock public
    boolean
    Enable locking for file reading and writing
  • $name public
    string
    Filename
  • $path public
    mixed
    Path property

Method Summary

  • __construct() public
    Constructor
  • __destruct() public
    Closes the current file if it is opened
  • append() public
    Append given data string to this File.
  • close() public
    Closes the current file if it is opened.
  • copy() public
    Copy the File to $dest
  • create() public
    Creates the File.
  • delete() public
    Deletes the File.
  • executable() public
    Returns true if the File is executable.
  • exists() public
    Returns true if the File exists.
  • ext() public
    Returns the File extension.
  • folder() public
    Returns the current folder.
  • group() public
    Returns the File's group.
  • info() public
    Returns the File info as an array with the following keys:
  • lastAccess() public
    Returns last access time.
  • lastChange() public
    Returns last modified time.
  • md5() public
    Get md5 Checksum of file with previous check of Filesize
  • mime() public

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

  • name() public
    Returns the File name without extension.
  • offset() public
    Sets or gets the offset for the currently opened file.
  • open() public
    Opens the current file with a given $mode
  • owner() public
    Returns the File's owner.
  • perms() public
    Returns the "chmod" (permissions) of the File.
  • prepare() public static

    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"

  • pwd() public
    Returns the full path of the File.
  • read() public
    Return the contents of this File as a string.
  • readable() public
    Returns true if the File is readable.
  • safe() public
    makes filename safe for saving
  • size() public
    Returns the Filesize
  • writable() public
    Returns true if the File is writable.
  • write() public
    Write given data to this File.

Method Detail

__construct() 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

__destruct() public ¶

__destruct( )

Closes the current file if it is opened

append() 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

close() 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

copy() 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

create() public ¶

create( )

Creates the File.

Returns
boolean
Success
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::create

delete() public ¶

delete( )

Deletes the File.

Returns
boolean
Success
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::delete

executable() public ¶

executable( )

Returns true if the File is executable.

Returns
boolean
true if its executable, false otherwise
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::executable

exists() public ¶

exists( )

Returns true if the File exists.

Returns
boolean
true if it exists, false otherwise
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::exists

ext() public ¶

ext( )

Returns the File extension.

Returns
string
The File extension
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::ext

folder() public ¶

folder( )

Returns the current folder.

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

group() public ¶

group( )

Returns the File's group.

Returns
integer
the Filegroup
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::group

info() 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

lastAccess() public ¶

lastAccess( )

Returns last access time.

Returns
integer
timestamp Timestamp of last access time
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::lastAccess

lastChange() public ¶

lastChange( )

Returns last modified time.

Returns
integer
timestamp Timestamp of last modification
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::lastChange

md5() 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
md5 Checksum See md5_file()
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::md5

mime() 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.

name() public ¶

name( )

Returns the File name without extension.

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

offset() 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

open() 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

owner() public ¶

owner( )

Returns the File's owner.

Returns
integer
the Fileowner
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::owner

perms() public ¶

perms( )

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

Returns
string
Permissions for the file
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::perms

prepare() public static ¶

prepare( string $data , boolean $forceWindows = false )

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
Data to prepare for writing.
boolean $forceWindows optional false
Returns
string
The with converted line endings.
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::prepare

pwd() public ¶

pwd( )

Returns the full path of the File.

Returns
string
Full path to file
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::pwd

read() 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

readable() public ¶

readable( )

Returns true if the File is readable.

Returns
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() public ¶

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

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
Returns
string
$ext the extension of the file
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::safe

size() public ¶

size( )

Returns the Filesize

Returns
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() public ¶

writable( )

Returns true if the File is writable.

Returns
boolean
true if its writable, false otherwise
Link
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::writable

write() 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 detail

$Folder ¶

public Folder

Folder object of the File

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

$handle ¶

public resource

Holds the file handler resource if the file is opened

null

$info ¶

public array

File info

array()

$lock ¶

public boolean

Enable locking for file reading and writing

null

$name ¶

public string

Filename

null

$path ¶

public mixed

Path property

Current file's absolute path

null
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs