include/utils/file_utils.php
Functions
cleanDirName(
string $name
)
:
stringFilter dir name to not contain path components - no slashes, no .., etc.
| Name | Type | Description |
|---|---|---|
| $name | string |
| Type | Description |
|---|---|
| string |
clean_path(
string $path
)
:
stringConvert all \ to / in path, remove multiple '/'s and '/./'
| Name | Type | Description |
|---|---|---|
| $path | string |
| Type | Description |
|---|---|
| string |
createFTSLogicHook(
$filePath
=
'application/Ext/LogicHooks/logichooks.ext.php'
)
:
void| Name | Type | Description |
|---|---|---|
| $filePath |
generateMD5array(
\$path $path, \$ignore_dirs $ignore_dirs
=
array('cache', 'upload')
)
:
voidThis function will recursively generates md5s of files and returns an array of all md5s.
| Name | Type | Description |
|---|---|---|
| $path | \$path | The path of the root directory to scan - must end with '/' |
| $ignore_dirs | \$ignore_dirs | array of filenames/directory names to ignore running md5 on - default 'cache' and 'upload' |
- Result
- $md5_array an array containing path as key and md5 as value
getFiles(
array $arr, string $dir, \regex $pattern
=
null
)
:
voidFunction to retrieve all file names of matching pattern in a directory (and it's subdirectories) example: getFiles($arr, './modules', '.+/EditView.php/'); // grabs all EditView.phps
| Name | Type | Description |
|---|---|---|
| $arr | array | return array to populate matches |
| $dir | string | directory to look in [ USE ./ in front of the $dir! ] |
| $pattern | \regex | optional pattern to match against |
get_file_extension(
\$filename $filename, \$string_to_lower $string_to_lower
=
true
)
:
\extensionget_file_extension This function returns the file extension portion of a given filename
| Name | Type | Description |
|---|---|---|
| $filename | \$filename | String of filename to return extension |
| $string_to_lower | \$string_to_lower | boolean value indicating whether or not to return value as lowercase, true by default |
| Type | Description |
|---|---|
| \extension | String value, blank if no extension found |
get_mime_content_type_from_filename(
\$filename $filename
)
:
\mimeget_mime_content_type_from_filename This function is similar to mime_content_type, but does not require a real file or path location. Instead, the function merely checks the filename extension and returns a best guess mime content type.
| Name | Type | Description |
|---|---|---|
| $filename | \$filename | String of filename to return mime content type |
| Type | Description |
|---|---|
| \mime | content type as String value (defaults to 'application/octet-stream' for filenames with extension, empty otherwise) |
md5DirCompare(
\$path_a $path_a, \$path_b $path_b, \$ignore_dirs $ignore_dirs
=
array('cache', 'upload')
)
:
voidFunction to compare two directory structures and return the items in path_a that didn't match in path_b
| Name | Type | Description |
|---|---|---|
| $path_a | \$path_a | The path of the first root directory to scan - must end with '/' |
| $path_b | \$path_b | The path of the second root directory to scan - must end with '/' |
| $ignore_dirs | \$ignore_dirs | array of filenames/directory names to ignore running md5 on - default 'cache' and 'upload' |
- Result
- array containing all the md5s of everything in $path_a that didn't have a match in $path_b
readfile_chunked(
string $filename, int $retbytes
=
true
)
:
voidFunction to split up large files for download used in download.php
| Name | Type | Description |
|---|---|---|
| $filename | string | |
| $retbytes | int |
sugar_rename(
string $old_filename, string $new_filename
)
:
voidRenames a file. If $new_file already exists, it will first unlink it and then rename it.
used in SugarLogger.php
| Name | Type | Description |
|---|---|---|
| $old_filename | string | |
| $new_filename | string |
write_array_to_file(
$the_name, $the_array, $the_file, $mode
=
"w", $header
=
''
)
:
void| Name | Type | Description |
|---|---|---|
| $the_name | ||
| $the_array | ||
| $the_file | ||
| $mode | ||
| $header |