CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 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

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • File
  • Folder

Class File

Convenience class for reading, writing and appending to files.

Namespace: Cake\Filesystem
Location: Filesystem/File.php

Properties summary

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

Method Summary

  • __construct() public
    Constructor
  • __destruct() public
    Closes the current file if it is opened
  • _basename() protected static
    Returns the file basename. simulate the php basename() for multibyte (mb_basename).
  • append() public
    Append given data string to this file.
  • clearStatCache() public
    Clear PHP's internal stat cache
  • 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

    Gets the mime type of the file. Uses the finfo extension if it's 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 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"

  • 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.
  • replaceText() public
    Searches for a given text and replaces the text if found.
  • safe() public
    Makes file name safe for saving
  • size() public
    Returns the file size
  • 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
https://book.cakephp.org/3.0/en/core-libraries/file-folder.html#file-api

__destruct() public ¶

__destruct( )

Closes the current file if it is opened

_basename() protected static ¶

_basename( string $path , string|null $ext = null )

Returns the file basename. simulate the php basename() for multibyte (mb_basename).

Parameters
string $path
Path to file
string|null $ext optional null
The name of the extension
Returns
string
the file basename.

append() public ¶

append( string $data , boolean $force = false )

Append given data string to this file.

Parameters
string $data
Data to write
boolean $force optional false
Force the file to open
Returns
boolean
Success

clearStatCache() public ¶

clearStatCache( boolean $all = false )

Clear PHP's internal stat cache

Parameters
boolean $all optional false

Clear all cache or not. Passing false will clear the stat cache for the current path only.

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

copy() public ¶

copy( string $dest , boolean $overwrite = true )

Copy the File to $dest

Parameters
string $dest
Absolute path to copy the file to.
boolean $overwrite optional true
Overwrite $dest if exists
Returns
boolean
Success

create() public ¶

create( )

Creates the file.

Returns
boolean
Success

delete() public ¶

delete( )

Deletes the file.

Returns
boolean
Success

executable() public ¶

executable( )

Returns true if the File is executable.

Returns
boolean
True if it's executable, false otherwise

exists() public ¶

exists( )

Returns true if the file exists.

Returns
boolean
True if it exists, false otherwise

ext() public ¶

ext( )

Returns the file extension.

Returns
string|false
The file extension, false if extension cannot be extracted.

folder() public ¶

folder( )

Returns the current folder.

Returns
Cake\Filesystem\Folder
Current folder

group() public ¶

group( )

Returns the file's group.

Returns
integer|false
The file group, or false in case of an error

info() public ¶

info( )

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

  • dirname
  • basename
  • extension
  • filename
  • filesize
  • mime
Returns
array
File information.

lastAccess() public ¶

lastAccess( )

Returns last access time.

Returns
integer|false
Timestamp of last access time, or false in case of an error

lastChange() public ¶

lastChange( )

Returns last modified time.

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

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|false
md5 Checksum See md5_file(), or false in case of an error

mime() public ¶

mime( )

Gets the mime type of the file. Uses the finfo extension if it's available, otherwise falls back to mime_content_type().

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

name() public ¶

name( )

Returns the file name without extension.

Returns
string|false
The file name without extension, false if name cannot be extracted.

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
integer|boolean
True on success, false on failure (set mode), false on failure or integer offset on success (get mode)

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

owner() public ¶

owner( )

Returns the file's owner.

Returns
integer|false
The file owner, or false in case of an error

perms() public ¶

perms( )

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

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

prepare() 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 Windows new line string.
Returns
string
The with converted line endings.

pwd() public ¶

pwd( )

Returns the full path of the file.

Returns
string
Full path to the file

read() public ¶

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

Return the contents of this file as a string.

Parameters
string|boolean $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
string|false
string on success, false on failure

readable() public ¶

readable( )

Returns true if the file is readable.

Returns
boolean
True if file is readable, false otherwise

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

safe() public ¶

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

Makes file name safe for saving

Parameters
string|null $name optional null
The name of the file to make safe if different from $this->name
string|null $ext optional null
The name of the extension to make safe if different from $this->ext
Returns
string
The extension of the file

size() public ¶

size( )

Returns the file size

Returns
integer|false
Size of the file in bytes, or false in case of an error

writable() public ¶

writable( )

Returns true if the file is writable.

Returns
boolean
True if it's writable, false otherwise

write() public ¶

write( string $data , string $mode = 'w' , boolean $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().
boolean $force optional false
Force the file to open
Returns
boolean
Success

Properties detail

$Folder ¶

public Cake\Filesystem\Folder

Folder object of the file

Link
https://book.cakephp.org/3.0/en/core-libraries/file-folder.html

$handle ¶

public resource|null

Holds the file handler resource if the file is opened

$info ¶

public array

File info

[]

$lock ¶

public boolean|null

Enable locking for file reading and writing

$name ¶

public string

File name

$path ¶

public string|null

Path property

Current file's absolute path

Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs