boa框架开发手册v5.2

file类
版本 1.0+
命名空间 boa
文件 boa/file.php
说明 文件系统操作类,继承base类,配置:'FILE' => [],
配置
配置项 默认值 类型 说明
mode 0755 int 创建目录时的模式,八进制值
safe_mode false bool 是否开启安全模式
safe_path BS_WWW string 安全模式下仅允许在该目录下操作
目录
方法 说明
read() 读文件
write() 写文件
chmod() 改变目录下文件模式
realpath() 从相对路径计算绝对路径
read_dir() 读取目录,受safe_mode影响
copy_dir() 拷贝目录,受safe_mode影响
clear_dir() 清理目录,受safe_mode影响
count_dir() 统计目录
replace_dir() 内容查找替换,受safe_mode影响
preg_replace_dir() 使用正则查找替换内容,受safe_mode影响
方法

read()

说明
读文件
参数 必须 默认值 类型 说明
$file Y string 文件路径
$maxlen 0 int 最大读取长度,默认读取全部
$offset -1 int 读取位置,默认从头读取
返回值
成功返回内容(string);失败返回false(bool)

write()

说明
写文件
参数 必须 默认值 类型 说明
$file Y string 文件路径,不存在则自动创建
$str Y string 待写入内容
$flag 0 int 可选值:FILE_USE_INCLUDE_PATH, FILE_APPEND, LOCK_EX
返回值
成功返回写入字节数(int),失败返回false(bool)

chmod()

说明
改变目录下文件模式
参数 必须 默认值 类型 说明
$path Y string 目录
$mode 0755 int 文件模式
返回值
成功返回true(bool);失败返回false(bool)

realpath()

说明
从相对路径计算绝对路径
参数 必须 默认值 类型 说明
$path Y string 相对路径
$exists false bool 检测文件是否真实存在
返回值
成功返回路径(string);失败返回false(bool)

read_dir()

说明
读取目录,受safe_mode影响
参数 必须 默认值 类型 说明
$path Y string 目录路径
$type 0 int 返回类型;1=目录,2=文件,0=全部
返回值
成功依据type返回结果(array);失败返回false(bool)

copy_dir()

说明
拷贝目录,受safe_mode影响
参数 必须 默认值 类型 说明
$source Y string 源路径
$dest Y string 目标路径
$override false bool 文件存在时是否覆盖
返回值
成功返回true(bool);失败返回false(bool)

clear_dir()

说明
清理目录,受safe_mode影响
参数 必须 默认值 类型 说明
$path Y string 目录
$deldir false bool 是否删除当前目录
返回值
成功返回true(bool);失败返回false(bool)

count_dir()

说明
统计目录
参数 必须 默认值 类型 说明
$path Y string 目录
$recursive false bool 是否递归子目录
返回值
返回统计信息(array)

replace_dir()

说明
内容查找替换,受safe_mode影响
参数 必须 默认值 类型 说明
$path Y string 查找目录
$search Y string 查找内容
$repalce string 替换内容
$exts null string 限定文件后缀,如:php|txt|ini
返回值
成功返回true(bool);失败返回false(bool)

preg_replace_dir()

说明
使用正则查找替换内容,受safe_mode影响
参数 必须 默认值 类型 说明
$path Y string 查找目录
$search Y string 查找内容,正则表达式
$repalce string 替换内容
$filter null string 过滤器,正则表达式
返回值
成功返回true(bool);失败返回false(bool)