Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • CDateTimeParser
  • CFileHelper
  • CFormatter
  • CLocalizedFormatter
  • CMarkdownParser
  • CPasswordHelper
  • CPropertyValue
  • CTimestamp
  • CVarDumper
  • Overview
  • Package
  • Class
  • Tree

Class CFileHelper

CFileHelper provides a set of helper methods for common file system operations.

Package: system\utils
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/utils/CFileHelper.php
Methods summary
public static string
# getExtension( string $path )

Returns the extension name of a file path. For example, the path "path/to/something.php" would return "php".

Returns the extension name of a file path. For example, the path "path/to/something.php" would return "php".

Parameters

$path
string
$path the file path

Returns

string
the extension name without the dot character.

Since

1.1.2
public static
# copyDirectory( string $src, string $dst, array $options = array() )

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

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

Parameters

$src
string
$src the source directory
$dst
string
$dst the destination directory
$options
array
$options 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'. Note, that '/' should be used as separator regardless of the value of the DIRECTORY_SEPARATOR constant.
  • 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.
  • newDirMode - the permission to be set for newly copied directories (defaults to 0777);
  • newFileMode - the permission to be set for newly copied files (defaults to the current environment setting).
public static
# removeDirectory( string $directory, array $options = array() )

Removes a directory recursively.

Removes a directory recursively.

Parameters

$directory
string
$directory to be deleted recursively.
$options
array
$options for the directory removal. Valid options are:
  • traverseSymlinks: boolean, whether symlinks to the directories should be traversed too. Defaults to false, meaning that the content of the symlinked directory would not be deleted. Only symlink would be removed in that default case.
Note, options parameter is available since 1.1.16

Since

1.1.14
public static array
# findFiles( string $dir, array $options = array() )

Returns the files found under the specified directory and subdirectories.

Returns the files found under the specified directory and subdirectories.

Parameters

$dir
string
$dir the directory under which the files will be looked for
$options
array
$options 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'. Note, that '/' should be used as separator regardless of the value of the DIRECTORY_SEPARATOR constant.
  • 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.
  • absolutePaths: boolean, whether to return absolute paths or relative ones, defaults to true.

Returns

array
files found under the directory. The file list is sorted.
protected static
# copyDirectoryRecursive( string $src, string $dst, string $base, array $fileTypes, array $exclude, integer $level, array $options )

Copies a directory. This method is mainly used by CFileHelper::copyDirectory().

Copies a directory. This method is mainly used by CFileHelper::copyDirectory().

Parameters

$src
string
$src the source directory
$dst
string
$dst the destination directory
$base
string
$base the path relative to the original source directory
$fileTypes
array
$fileTypes list of file name suffix (without dot). Only files with these suffixes will be copied.
$exclude
array
$exclude 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'. Note, that '/' should be used as separator regardless of the value of the DIRECTORY_SEPARATOR constant.
$level
integer
$level 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.
$options
array
$options additional options. The following options are supported: newDirMode - the permission to be set for newly copied directories (defaults to 0777); newFileMode - the permission to be set for newly copied files (defaults to the current environment setting).
protected static array
# findFilesRecursive( string $dir, string $base, array $fileTypes, array $exclude, integer $level, boolean $absolutePaths )

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

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

Parameters

$dir
string
$dir the source directory
$base
string
$base the path relative to the original source directory
$fileTypes
array
$fileTypes list of file name suffix (without dot). Only files with these suffixes will be returned.
$exclude
array
$exclude 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'. Note, that '/' should be used as separator regardless of the value of the DIRECTORY_SEPARATOR constant.
$level
integer
$level 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.
$absolutePaths
boolean
$absolutePaths whether to return absolute paths or relative ones

Returns

array
files found under the directory.
protected static boolean
# validatePath( string $base, string $file, boolean $isFile, array $fileTypes, array $exclude )

Validates a file or directory.

Validates a file or directory.

Parameters

$base
string
$base the path relative to the original source directory
$file
string
$file the file or directory name
$isFile
boolean
$isFile whether this is a file
$fileTypes
array
$fileTypes list of valid file name suffixes (without dot).
$exclude
array
$exclude 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, false will be returned. For example, an exclusion of '.svn' will return false for all files and directories whose name is '.svn'. And an exclusion of '/a/b' will return false for file or directory '$src/a/b'. Note, that '/' should be used as separator regardless of the value of the DIRECTORY_SEPARATOR constant.

Returns

boolean
whether the file or directory is valid
public static string
# getMimeType( string $file, string $magicFile = null, boolean $checkExtension = true )
Determines the MIME type of the specified file. This method will attempt the following approaches in order:
  1. finfo
  2. mime_content_type
  3. CFileHelper::getMimeTypeByExtension(), when $checkExtension is set true.
Determines the MIME type of the specified file. This method will attempt the following approaches in order:
  1. finfo
  2. mime_content_type
  3. CFileHelper::getMimeTypeByExtension(), when $checkExtension is set true.

Parameters

$file
string
$file the file name.
$magicFile
string
$magicFile name of a magic database file, usually something like /path/to/magic.mime. This will be passed as the second parameter to finfo_open. Magic file format described in man 5 magic, note that this file does not contain a standard PHP array as you might suppose. Specified magic file will be used only when fileinfo PHP extension is available. This parameter has been available since version 1.1.3.
$checkExtension
boolean
$checkExtension whether to check the file extension in case the MIME type cannot be determined based on finfo and mime_content_type. Defaults to true. This parameter has been available since version 1.1.4.

Returns

string
the MIME type. Null is returned if the MIME type cannot be determined.
public static string
# getMimeTypeByExtension( string $file, string $magicFile = null )

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.

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.

Parameters

$file
string
$file the file name.
$magicFile
string
$magicFile the path of the file that contains all available MIME type information. If this is not set, the default 'system.utils.mimeTypes' file will be used. This parameter has been available since version 1.1.3.

Returns

string
the MIME type. Null is returned if the MIME type cannot be determined.
public static string
# getExtensionByMimeType( string $file, string $magicFile = null )

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

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

Parameters

$file
string
$file the file name.
$magicFile
string
$magicFile the path of the file that contains all available extension information. If this is not set, the default 'system.utils.fileExtensions' file will be used. This parameter has been available since version 1.1.16.

Returns

string
extension name. Null is returned if the extension cannot be determined.
public static boolean
# createDirectory( string $dst, integer $mode = null, boolean $recursive = false )

Shared environment safe version of mkdir. Supports recursive creation. For avoidance of umask side-effects chmod is used.

Shared environment safe version of mkdir. Supports recursive creation. For avoidance of umask side-effects chmod is used.

Parameters

$dst
string
$dst path to be created
$mode
integer
$mode the permission to be set for newly created directories, if not set - 0777 will be used
$recursive
boolean
$recursive whether to create directory structure recursive if parent dirs do not exist

Returns

boolean
result of mkdir

See

mkdir
API documentation generated by ApiGen 2.8.0