php yii2 finfo file,FileHelper:文件系统助手

本文介绍了PHP FileHelper类的三个核心方法:createDirectory用于创建目录,removeDirectory用于递归删除目录,copyDirectory实现目录复制。详细讲解了每个方法的参数和用法,有助于理解文件操作的高级技巧。
摘要由CSDN通过智能技术生成

#### FileHelper::createDirectory() 方法创建一个新目录.

~~~

/**

* @param string $path 要创建的目录的路径.

* @param int $mode 为新创建目录设置权限.

* @param bool $recursive 如果父目录不存在, 是否创建父目录.

* @return bool 是否成功创建目录.

*/

FileHelper::createDirectory($path, $mode = 0775, $recursive = true);

~~~

#### FileHelper::removeDirectory() 方法递归删除目录(及其所有内容).

~~~

/**

* @param string $dir 要递归删除的目录.

* @param array $options 删除目录的选项. 有效的选项有:

* - traverseSymlinks: boolean, 是否应该遍历目录的快捷方式.

* 默认为`false`, 意味着只会删除快捷方式, 而不删除快捷方式目录里的内容.

*/

FileHelper::removeDirectory($dir, $options = []);

~~~

#### FileHelper::copyDirectory() 方法将整个目录复制为另一个目录.

~~~

/**

* Copies a whole directory as another one.

* The files and sub-directories will also be copied over.

* @param string $src 源目录.

* @param string $dst 目的目录.

* @param array $options 复制目录的选项. 有效的选项有:

* - dirMode: integer, the permission to be set for newly copied directories. Defaults to 0775.

* - fileMode: integer, the permission to be set for newly copied files. Defaults to the current environment setting.

* - filter: callback, a PHP callback that is called for each directory or file.

* The signature of the callback should be: `function ($path)`, where `$path` refers the full path to be filtered.

* The callback can return one of the following values:

*

* * true: the directory or file will be copied (the "only" and "except" options will be ignored)

* * false: the directory or file will NOT be copied (the "only" and "except" options will be ignored)

* * null: the "only" and "except" options will determine whether the directory or file should be copied

*

* - only: array, list of patterns that the file paths should match if they want to be copied.

* A path matches a pattern if it contains the pattern string at its end.

* For example, '.php' matches all file paths ending with '.php'.

* Note, the '/' characters in a pattern matches both '/' and '\' in the paths.

* If a file path matches a pattern in both "only" and "except", it will NOT be copied.

* - except: array, list of patterns that the files or directories should match if they want to be excluded from being copied.

* A path matches a pattern if it contains the pattern string at its end.

* Patterns ending with '/' apply to directory paths only, and patterns not ending with '/'

* apply to file paths only. For example, '/a/b' matches all file paths ending with '/a/b';

* and '.svn/' matches directory paths ending with '.svn'. Note, the '/' characters in a pattern matches

* both '/' and '\' in the paths.

* - caseSensitive: boolean, whether patterns specified at "only" or "except" should be case sensitive. Defaults to true.

* - recursive: boolean, whether the files under the subdirectories should also be copied. Defaults to true.

* - beforeCopy: callback, a PHP callback that is called before copying each sub-directory or file.

* If the callback returns false, the copy operation for the sub-directory or file will be cancelled.

* The signature of the callback should be: `function ($from, $to)`, where `$from` is the sub-directory or

* file to be copied from, while `$to` is the copy target.

* - afterCopy: callback, a PHP callback that is called after each sub-directory or file is successfully copied.

* The signature of the callback should be: `function ($from, $to)`, where `$from` is the sub-directory or

* file copied from, while `$to` is the copy target.

* - copyEmptyDirectories: boolean, whether to copy empty directories. Set this to false to avoid creating directories

* that do not contain files. This affects directories that do not contain files initially as well as directories that

* do not contain files at the target destination because files have been filtered via `only` or `except`.

* Defaults to true. This option is available since version 2.0.12. Before 2.0.12 empty directories are always copied.

*/

FileHelper::copyDirectory($src, $dst, $options = []);

~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值