class File
File helper
As for all helpers, all methods are statics.
For convenience, the best practice is to use:
use Library\Helper\File as FileHelper;
Properties
static | $REPLACEMENT_FILENAMES_CHARS | List of characters replaced by a space in a file name to build a human readable string |
static | $FILESIZE_ORDERED_UNITS | List of units to build the size field, ordered by 1024 operator on original size |
Methods
static string |
getUniqFilename(string $filename = '', string $dir = null, boolean $force_file = true, string $extension = 'txt')
Returns a filename or directory that does not exist in the destination |
|
static string |
formatFilename(string $filename = '', boolean $lowercase = false, string $delimiter = '-')
Formatting file names |
|
static null|string |
getExtension(string $filename = '', bool $dot = false)
Returns the extension of a file name |
|
static string |
getHumanReadableFilename(string $filename = '')
Render a human readable string from a file name |
|
static int |
getTransformedFilesize(float|int $size, int $round = 3, string $dec_delimiter = ',')
Returns a formatted file size in bytes or derived unit |
|
static bool |
touch(string $file_path = null, array $logs = array())
Create an empty file or touch an existing file |
|
static bool |
remove(string $file_path = null, array $logs = array())
Remove a file if it exists |
|
static bool |
copy(string $file_path = null, string $target_path = null, bool $force = false, array $logs = array())
Copy file |
|
static bool |
write(string $file_path = null, string $content, string $type = 'a', bool $force = false, array $logs = array())
Write a content in a file |
Details
at line 51
static public string
getUniqFilename(string $filename = '', string $dir = null, boolean $force_file = true, string $extension = 'txt')
Returns a filename or directory that does not exist in the destination
at line 84
static public string
formatFilename(string $filename = '', boolean $lowercase = false, string $delimiter = '-')
Formatting file names
at line 123
static public null|string
getExtension(string $filename = '', bool $dot = false)
Returns the extension of a file name
It basically returns everything after last dot. No validation is done.
at line 146
static public string
getHumanReadableFilename(string $filename = '')
Render a human readable string from a file name
The original file name is rebuilt striping the extension and a set of commonly used separator characters in file or directories names.
at line 174
static public int
getTransformedFilesize(float|int $size, int $round = 3, string $dec_delimiter = ',')
Returns a formatted file size in bytes or derived unit
This will return the size received transforming it to be readable, with the appropriate
unit chosen in self::$FILESIZE_ORDERED_UNITS
.
at line 204
static public bool
touch(string $file_path = null, array $logs = array())
Create an empty file or touch an existing file
at line 231
static public bool
remove(string $file_path = null, array $logs = array())
Remove a file if it exists
at line 258
static public bool
copy(string $file_path = null, string $target_path = null, bool $force = false, array $logs = array())
Copy file $file_path
if it exists to $target_path
at line 295
static public bool
write(string $file_path = null, string $content, string $type = 'a', bool $force = false, array $logs = array())
Write a content in a file