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
stringThe full file path- buffer
stringThe buffer to write- useStreams
boolUse streams
Response
boolTrue 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
boolTRUE 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
stringThe path to the source file- dest
stringThe path to the destination file- path
stringAn optional base path to prefix to the file names- useStreams
boolTrue to use streams
Response
boolTrue 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
mixedThe file name or an array of file names
Response
boolTrue 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
stringFile path
Response
boolTrue if path is a file
getExt
Gets the extension of a file name
getExt( file) :
| since |
1.7.0 |
|---|
Arguments
- file
stringThe file name
Response
stringThe 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
stringThe path to the file just written to, to flush from opcache- force
boolIf set to true, the script will be invalidated regardless of whether invalidation is necessary
Response
boolTRUE 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
stringThe name of the file [not full path]
Response
stringThe 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
stringThe path to the source file- dest
stringThe path to the destination file- path
stringAn optional base path to prefix to the file names- useStreams
boolTrue to use streams
Response
boolTrue 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
stringThe file name
Response
stringThe 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
stringThe name of the php (temporary) uploaded file- dest
stringThe path (including filename) to move the uploaded file to- useStreams
boolTrue to use streams- allowUnsafe
boolAllow the upload of unsafe files- safeFileOptions
array<string|int, mixed>Options to InputFilter::isSafeFile
Response
boolTrue 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
stringThe full file path- buffer
stringThe buffer to write- useStreams
boolUse streams
Response
boolTrue on success
Properties
canFlushFileCache
true if OPCache enabled, and we have permission to invalidate files
| since |
4.0.1 |
|---|
Type(s)
bool