Convenience class for reading, writing and appending to files.
Cake\Filesystem\FolderFolder object of the file
resource|nullHolds the file handler resource if the file is opened
array<string, mixed>File info
bool|nullEnable locking for file reading and writing
stringFile name
string|nullPath property
Constructor
Closes the current file if it is opened
Returns the file basename. simulate the php basename() for multibyte (mb_basename).
Append given data string to this file.
Clear PHP's internal stat cache
Closes the current file if it is opened.
Copy the File to $dest
Creates the file.
Deletes the file.
Returns true if the File is executable.
Returns true if the file exists.
Returns the file extension.
Returns the current folder.
Returns the file's group.
Returns the file info as an array with the following keys:
Returns last access time.
Returns last modified time.
Get md5 Checksum of file with previous check of Filesize
Gets the mime type of the file. Uses the finfo extension if it's available, otherwise falls back to mime_content_type().
Returns the file name without extension.
Sets or gets the offset for the currently opened file.
Opens the current file with a given $mode
Returns the file's owner.
Returns the "chmod" (permissions) of the file.
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"
Returns the full path of the file.
Return the contents of this file as a string.
Returns true if the file is readable.
Searches for a given text and replaces the text if found.
Makes file name safe for saving
Returns the file size
Returns true if the file is writable.
Write given data to this file.
__construct(string $path, bool $create = false, int $mode = 0755)
Constructor
string $path Path to file
bool $create optional Create file if it does not exist (if true)
int $mode optional Mode to apply to the folder holding the file
__destruct()
Closes the current file if it is opened
_basename(string $path, string|null $ext = null): string
Returns the file basename. simulate the php basename() for multibyte (mb_basename).
string $path Path to file
string|null $ext optional The name of the extension
stringappend(string $data, bool $force = false): bool
Append given data string to this file.
string $data Data to write
bool $force optional Force the file to open
boolclearStatCache(bool $all = false): void
Clear PHP's internal stat cache
bool $all optional Clear all cache or not. Passing false will clear the stat cache for the current path only.
voidclose(): bool
Closes the current file if it is opened.
boolcopy(string $dest, bool $overwrite = true): bool
Copy the File to $dest
string $dest Absolute path to copy the file to.
bool $overwrite optional Overwrite $dest if exists
boolcreate(): bool
Creates the file.
booldelete(): bool
Deletes the file.
boolexecutable(): bool
Returns true if the File is executable.
boolexists(): bool
Returns true if the file exists.
boolext(): string|false
Returns the file extension.
string|falsefolder(): Cake\Filesystem\Folder
Returns the current folder.
Cake\Filesystem\Foldergroup(): int|false
Returns the file's group.
int|falseinfo(): array<string, mixed>
Returns the file info as an array with the following keys:
array<string, mixed>lastAccess(): int|false
Returns last access time.
int|falselastChange(): int|false
Returns last modified time.
int|falsemd5(int|true $maxsize = 5): string|false
Get md5 Checksum of file with previous check of Filesize
int|true $maxsize optional in MB or true to force
string|falsemime(): string|false
Gets the mime type of the file. Uses the finfo extension if it's available, otherwise falls back to mime_content_type().
string|falsename(): string|false
Returns the file name without extension.
string|falseoffset(int|false $offset = false, int $seek = SEEK_SET): int|bool
Sets or gets the offset for the currently opened file.
int|false $offset optional The $offset in bytes to seek. If set to false then the current offset is returned.
int $seek optional PHP Constant SEEK_SET | SEEK_CUR | SEEK_END determining what the $offset is relative to
int|boolopen(string $mode = 'r', bool $force = false): bool
Opens the current file with a given $mode
string $mode optional A valid 'fopen' mode string (r|w|a ...)
bool $force optional If true then the file will be re-opened even if its already opened, otherwise it won't
boolowner(): int|false
Returns the file's owner.
int|falseperms(): string|false
Returns the "chmod" (permissions) of the file.
string|falseprepare(string $data, bool $forceWindows = false): string
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"
string $data Data to prepare for writing.
bool $forceWindows optional If true forces Windows new line string.
stringpwd(): string|null
Returns the full path of the file.
string|nullread(string|false $bytes = false, string $mode = 'rb', bool $force = false): string|false
Return the contents of this file as a string.
string|false $bytes optional where to start
string $mode optional A fread compatible mode.
bool $force optional If true then the file will be re-opened even if its already opened, otherwise it won't
string|falsereadable(): bool
Returns true if the file is readable.
boolreplaceText(array<string>|string $search, array<string>|string $replace): bool
Searches for a given text and replaces the text if found.
array<string>|string $search Text(s) to search for.
array<string>|string $replace Text(s) to replace with.
boolsafe(string|null $name = null, string|null $ext = null): string
Makes file name safe for saving
string|null $name optional The name of the file to make safe if different from $this->name
string|null $ext optional The name of the extension to make safe if different from $this->ext
stringsize(): int|false
Returns the file size
int|falsewritable(): bool
Returns true if the file is writable.
boolwrite(string $data, string $mode = 'w', bool $force = false): bool
Write given data to this file.
string $data Data to write to this File.
string $mode optional Mode of writing. {@link https://secure.php.net/fwrite See fwrite()}.
bool $force optional Force the file to open
boolFolder object of the file
Cake\Filesystem\FolderHolds the file handler resource if the file is opened
resource|nullFile info
array<string, mixed>Enable locking for file reading and writing
bool|nullFile name
stringPath property
Current file's absolute path
string|null
© 2005–present 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.
https://api.cakephp.org/4.4/class-Cake.Filesystem.File.html