system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.i18n system.i18n.gettext system.logging system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers

CFileHelper

system.utils
继承 class CFileHelper
可用自 1.0
版本 $Id$
CFileHelper provides a set of helper methods for common file system operations.

公共方法

隐藏继承的方法

方法描述被定义在
copyDirectory() Copies a directory recursively as another. CFileHelper
findFiles() Returns the files found under the specified directory and subdirectories. CFileHelper
getMimeType() Determines the MIME type of the specified file. CFileHelper
getMimeTypeByExtension() Determines the MIME type based on the extension name of the specified file. CFileHelper

受保护的方法

隐藏继承的方法

方法描述被定义在
copyDirectoryRecursive() Copies a directory. CFileHelper
findFilesRecursive() Returns the files found under the specified directory and subdirectories. CFileHelper
validatePath() Validates a file or directory. CFileHelper

方法详情

copyDirectory() 方法
public static void copyDirectory(string $src, string $dst, array $options=array ( ))
$src string the source directory
$dst string the destination directory
$options array options for directory copy. Valid options are:
  • fileTypes: array, list of file name suffix (without dot). Only files with these suffixes will be copied.
  • exclude: array, list of directory and file exclusions. Each exclusion can be either a name or a path. If a file or directory name or path matches the exclusion, it will not be copied. For example, an exclusion of '.svn' will exclude all files and directories whose name is '.svn'. And an exclusion of '/a/b' will exclude file or directory '$src/a/b'.
  • level: integer, recursion depth, default=-1. Level -1 means copying all directories and files under the directory; Level 0 means copying only the files DIRECTLY under the directory; level N means copying those directories that are within N levels.

Copies a directory recursively as another. If the destination directory does not exist, it will be created.

copyDirectoryRecursive() 方法
protected static void copyDirectoryRecursive(string $src, string $dst, string $base, array $fileTypes, array $exclude, integer $level)
$src string the source directory
$dst string the destination directory
$base string the path relative to the original source directory
$fileTypes array list of file name suffix (without dot). Only files with these suffixes will be copied.
$exclude array list of directory and file exclusions. Each exclusion can be either a name or a path. If a file or directory name or path matches the exclusion, it will not be copied. For example, an exclusion of '.svn' will exclude all files and directories whose name is '.svn'. And an exclusion of '/a/b' will exclude file or directory '$src/a/b'.
$level integer recursion depth. It defaults to -1. Level -1 means copying all directories and files under the directory; Level 0 means copying only the files DIRECTLY under the directory; level N means copying those directories that are within N levels.

Copies a directory. This method is mainly used by copyDirectory.

findFiles() 方法
public static array findFiles(string $dir, array $options=array ( ))
$dir string the directory under which the files will be looked for
$options array options for file searching. Valid options are:
  • fileTypes: array, list of file name suffix (without dot). Only files with these suffixes will be returned.
  • exclude: array, list of directory and file exclusions. Each exclusion can be either a name or a path. If a file or directory name or path matches the exclusion, it will not be copied. For example, an exclusion of '.svn' will exclude all files and directories whose name is '.svn'. And an exclusion of '/a/b' will exclude file or directory '$src/a/b'.
  • level: integer, recursion depth, default=-1. Level -1 means searching for all directories and files under the directory; Level 0 means searching for only the files DIRECTLY under the directory; level N means searching for those directories that are within N levels.
{return} array files found under the directory. The file list is sorted.

Returns the files found under the specified directory and subdirectories.

findFilesRecursive() 方法
protected static array findFilesRecursive(string $dir, string $base, array $fileTypes, array $exclude, integer $level)
$dir string the source directory
$base string the path relative to the original source directory
$fileTypes array list of file name suffix (without dot). Only files with these suffixes will be returned.
$exclude array list of directory and file exclusions. Each exclusion can be either a name or a path. If a file or directory name or path matches the exclusion, it will not be copied. For example, an exclusion of '.svn' will exclude all files and directories whose name is '.svn'. And an exclusion of '/a/b' will exclude file or directory '$src/a/b'.
$level integer recursion depth. It defaults to -1. Level -1 means searching for all directories and files under the directory; Level 0 means searching for only the files DIRECTLY under the directory; level N means searching for those directories that are within N levels.
{return} array files found under the directory.

Returns the files found under the specified directory and subdirectories. This method is mainly used by findFiles.

getMimeType() 方法
public static string getMimeType(string $file)
$file string the file name.
{return} string the MIME type. Null is returned if the MIME type cannot be determined.

Determines the MIME type of the specified file. This method will attempt the following approaches in order:

  1. finfo
  2. mime_content_type
  3. getMimeTypeByExtension

getMimeTypeByExtension() 方法
public static string getMimeTypeByExtension(string $file)
$file string the file name.
{return} string the MIME type. Null is returned if the MIME type cannot be determined.

Determines the MIME type based on the extension name of the specified file. This method will use a local map between extension name and MIME type.

validatePath() 方法
protected static boolean validatePath(string $base, string $file, boolean $isFile, array $fileTypes, array $exclude)
$base string the path relative to the original source directory
$file string the file or directory name
$isFile boolean whether this is a file
$fileTypes array list of file name suffix (without dot). Only files with these suffixes will be copied.
$exclude array list of directory and file exclusions. Each exclusion can be either a name or a path. If a file or directory name or path matches the exclusion, it will not be copied. For example, an exclusion of '.svn' will exclude all files and directories whose name is '.svn'. And an exclusion of '/a/b' will exclude file or directory '$src/a/b'.
{return} boolean whether the file or directory is valid

Validates a file or directory.