CRM_Utils_File
class CRM_Utils_File
class to provide simple static functions for file objects
Methods
Given a file name, determine if the file contents make it an ascii file
Given a file name, determine if the file contents make it an html file
Create a directory given a path name, creates parent directories if needed
Delete a directory given a path name, delete children directories and files if needed
Concatenate several files.
No description
Given a file name, recode it (in place!) to UTF-8
Appends a slash to the end of a string if it doesn't already end with one
Save a fake file somewhere
No description
No description
Strips comment from a possibly multiline SQL string
No description
Determine whether a given file is listed in the PHP include path.
Remove the 32 bit md5 we add to the fileName also remove the unknown tag if we added it.
Make a valid file name.
Copies a file
Get files for the extension.
Restrict access to a given directory (by planting there a restrictive .htaccess file)
Restrict remote users from browsing the given directory.
(Deprecated) Create the file-path from which all other internal paths are
computed. This implementation determines it as dirname(CIVICRM_TEMPLATE_COMPILEDIR)
.
Determine if a path is absolute.
No description
Make a file path relative to some base dir.
Create a path to a temporary file which can endure for multiple requests.
Create a path to a temporary directory which can endure for multiple requests.
Search directory tree for files which match a glob pattern.
Determine if $child is a sub-directory of $parent
Move $fromDir to $toDir, replacing/deleting any pre-existing content.
Format file.
Return formatted file URL, like for image file return image url with image icon
Return formatted image icon
Resize an image.
Get file icon class for specific MIME Type
Is the filename a safe and valid filename passed in from URL
Get the extensions that this MimeTpe is for
Get the extension of a file based on its path
Details
at line 48
static bool
isAscii(string $name)
Given a file name, determine if the file contents make it an ascii file
at line 76
static bool
isHtml(string $name)
Given a file name, determine if the file contents make it an html file
at line 110
static bool|NULL
createDir(string $path, bool $abort = TRUE)
Create a directory given a path name, creates parent directories if needed
at line 141
static
cleanDir(string $target, bool $rmdir = TRUE, bool $verbose = TRUE)
Delete a directory given a path name, delete children directories and files if needed
at line 187
static string
concat(array $files, string $delim = '')
Concatenate several files.
at line 204
static
copyDir(string $source, string $destination)
at line 230
static bool
toUtf8(string $name)
Given a file name, recode it (in place!) to UTF-8
at line 276
static string
addTrailingSlash(string $path, string $slash = NULL)
Appends a slash to the end of a string if it doesn't already end with one
at line 301
static string
createFakeFile(string $dir, string $contents = 'delete me', string $fileName = NULL)
Save a fake file somewhere
at line 319
static
sourceSQLFile(string|NULL $dsn, string $fileName, string $prefix = NULL, bool $dieOnErrors = TRUE)
at line 336
static
runSqlQuery(string|NULL $dsn, string $queryString, string $prefix = NULL, bool $dieOnErrors = TRUE)
at line 388
static string
stripComments(string $string)
Strips comment from a possibly multiline SQL string
at line 397
static bool
isExtensionSafe($ext)
at line 430
static bool
isIncludable(string $name)
Determine whether a given file is listed in the PHP include path.
at line 448
static mixed
cleanFileName($name)
Remove the 32 bit md5 we add to the fileName also remove the unknown tag if we added it.
at line 461
static string
makeFileName(string $name)
Make a valid file name.
at line 484
static mixed
duplicate($filePath)
Copies a file
at line 501
static array
getFilesByExtension(string $path, string $ext)
Get files for the extension.
at line 522
static
restrictAccess(string $dir, bool $overwrite = FALSE)
Restrict access to a given directory (by planting there a restrictive .htaccess file)
at line 556
static
restrictBrowsing($publicDir)
Restrict remote users from browsing the given directory.
at line 594
static
baseFilePath()
deprecated
deprecated
(Deprecated) Create the file-path from which all other internal paths are
computed. This implementation determines it as dirname(CIVICRM_TEMPLATE_COMPILEDIR)
.
This approach is problematic - e.g. it prevents one from authentically splitting the CIVICRM_TEMPLATE_COMPILEDIR away from other dirs. The implementation is preserved for backwards compatibility (and should only be called by CMS-adapters and by Civi\Core\Paths).
Do not use it for new path construction logic. Instead, use Civi::paths().
at line 627
static bool
isAbsolute(string $path)
Determine if a path is absolute.
at line 648
static string
relativeDirectory($directory)
deprecated
deprecated
at line 678
static string
absoluteDirectory($directory, string $basePath)
at line 710
static string
relativize($directory, $basePath)
Make a file path relative to some base dir.
at line 733
static string,
tempnam(string $prefix = 'tmp-')
Create a path to a temporary file which can endure for multiple requests.
at line 751
static string,
tempdir(string $prefix = 'tmp-')
Create a path to a temporary directory which can endure for multiple requests.
at line 771
static array(string)
findFiles(string $dir, string $pattern, bool $relative = FALSE)
Search directory tree for files which match a glob pattern.
Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
at line 813
static bool
isChildPath(string $parent, string $child, bool $checkRealPath = TRUE)
Determine if $child is a sub-directory of $parent
at line 848
static bool
replaceDir(string $fromDir, string $toDir, bool $verbose = FALSE)
Move $fromDir to $toDir, replacing/deleting any pre-existing content.
at line 872
static
formatFile(array $param, string $fileName, array $extraParams = [])
Format file.
at line 898
static string
getFileURL(string $path, string $fileType, string $url = NULL)
Return formatted file URL, like for image file return image url with image icon
at line 936
static string
getImageURL(string $imageURL)
Return formatted image icon
at line 991
static string
resizeImage(string $sourceFile, int $targetWidth, int $targetHeight, string $suffix = "", bool $preserveAspect = TRUE)
Resize an image.
at line 1064
static string
getIconFromMimeType(string $mimeType)
Get file icon class for specific MIME Type
at line 1083
static bool
isValidFileName(string $fileName = NULL)
Is the filename a safe and valid filename passed in from URL
at line 1101
static array
getAcceptableExtensionsForMimeType(string $mimeType = NULL)
Get the extensions that this MimeTpe is for
at line 1117
static string
getExtensionFromPath(string $path)
Get the extension of a file based on its path