File
A File handling class
since |
1.7.0 |
---|---|
deprecated |
4.4 will be removed in 6.0 Use Joomla\Filesystem\File instead. |
package |
Joomla CMS |
Methods
append
Append contents to a file
append( file, buffer, useStreams = false) :
since |
3.6.0 |
---|
Arguments
- file
string
The full file path- buffer
string
The buffer to write- useStreams
bool
Use streams
Response
bool
True on success
canFlushFileCache
First we check if opcache is enabled Then we check if the opcache_invalidate function is available Lastly we check if the host has restricted which scripts can use opcache_invalidate using opcache.restrict_api.
canFlushFileCache() :
$_SERVER['SCRIPT_FILENAME']
approximates the origin file's path, but realpath()
is necessary because SCRIPT_FILENAME
can be a relative path when run from CLI.
If the host has this set, check whether the path in opcache.restrict_api
matches
the beginning of the path of the origin file.
since |
4.0.1 |
---|---|
deprecated |
4.4 will be removed in 6.0 Use Joomla\Filesystem\File::invalidateFileCache() instead. This method will be removed without replacement. |
Response
bool
TRUE if we can proceed to use opcache_invalidate to flush a file from the OPCache
copy
Copies a file
copy( src, dest, path = null, useStreams = false) :
since |
1.7.0 |
---|---|
deprecated |
4.4 will be removed in 6.0 Use Joomla\Filesystem\File::copy() instead. The framework class throws Exceptions in case of error which you have to catch. |
Arguments
- src
string
The path to the source file- dest
string
The path to the destination file- path
string
An optional base path to prefix to the file names- useStreams
bool
True to use streams
Response
bool
True on success
delete
Delete a file or array of files
delete( file) :
since |
1.7.0 |
---|---|
deprecated |
4.4 will be removed in 6.0 Use Joomla\Filesystem\File::delete() instead. The framework class throws Exceptions in case of error which you have to catch. |
Arguments
- file
mixed
The file name or an array of file names
Response
bool
True on success
exists
Wrapper for the standard file_exists function
exists( file) :
since |
1.7.0 |
---|---|
deprecated |
4.4 will be removed in 6.0 Use is_file() instead. |
Arguments
- file
string
File path
Response
bool
True if path is a file
getExt
Gets the extension of a file name
getExt( file) :
since |
1.7.0 |
---|
Arguments
- file
string
The file name
Response
string
The file extension
invalidateFileCache
Invalidate opcache for a newly written/deleted file immediately, if opcache* functions exist and if this was a PHP file.
invalidateFileCache( filepath, force = true) :
since |
4.0.1 |
---|---|
deprecated |
4.4 will be removed in 6.0 Use Joomla\Filesystem\File::invalidateFileCache() instead. |
Arguments
- filepath
string
The path to the file just written to, to flush from opcache- force
bool
If set to true, the script will be invalidated regardless of whether invalidation is necessary
Response
bool
TRUE if the opcode cache for script was invalidated/nothing to invalidate,
or FALSE if the opcode cache is disabled or other conditions returning
FALSE from opcache_invalidate (like file not found).
makeSafe
Makes file name safe to use
makeSafe( file) :
since |
1.7.0 |
---|---|
deprecated |
4.4 will be removed in 6.0 Use Joomla\Filesystem\File::makeSafe() instead. |
Arguments
- file
string
The name of the file [not full path]
Response
string
The sanitised string
move
Moves a file
move( src, dest, path = '', useStreams = false) :
since |
1.7.0 |
---|---|
deprecated |
4.4 will be removed in 6.0 Use Joomla\Filesystem\File::move() instead. The framework class throws Exceptions in case of error which you have to catch. |
Arguments
- src
string
The path to the source file- dest
string
The path to the destination file- path
string
An optional base path to prefix to the file names- useStreams
bool
True to use streams
Response
bool
True on success
stripExt
Strips the last extension off of a file name
stripExt( file) :
since |
1.7.0 |
---|---|
deprecated |
4.4 will be removed in 6.0 Use Joomla\Filesystem\File::stripExt() instead. |
Arguments
- file
string
The file name
Response
string
The file name without the extension
upload
Moves an uploaded file to a destination folder
upload( src, dest, useStreams = false, allowUnsafe = false, mixed||string|int safeFileOptions = []) :
since |
1.7.0 |
---|---|
deprecated |
4.4 will be removed in 6.0 Use Joomla\Filesystem\File::upload() instead. The framework class throws Exceptions in case of error which you have to catch. |
Arguments
- src
string
The name of the php (temporary) uploaded file- dest
string
The path (including filename) to move the uploaded file to- useStreams
bool
True to use streams- allowUnsafe
bool
Allow the upload of unsafe files- safeFileOptions
array<string|int, mixed>
Options to InputFilter::isSafeFile
Response
bool
True on success
write
Write contents to a file
write( file, buffer, useStreams = false) :
since |
1.7.0 |
---|---|
deprecated |
4.4 will be removed in 6.0 Use Joomla\Filesystem\File::write() instead. |
Arguments
- file
string
The full file path- buffer
string
The buffer to write- useStreams
bool
Use streams
Response
bool
True on success
Properties
canFlushFileCache
true if OPCache enabled, and we have permission to invalidate files
since |
4.0.1 |
---|
Type(s)
bool