abstract class File extends FileSystem

Class File

Traits

Class Read

Constants

FORMAT_JSON

FORMAT_PHP

FORMAT_INI

FORMAT_YML

FORMAT_YAML

Methods

static bool
isAbsPath(string $path)

No description

static bool
isAbsolutePath(string $file)

Returns whether the file path is an absolute path.

static string
pathFormat(string $dirName)

转换为标准的路径结构

string
clearPharPath(string $path)

No description

static array|string
exists(string $file, null|string $type = null)

检查文件/夹/链接是否存在

static 
check(string $file, null|string|array $ext = null)

No description

static 
rename(string $origin, string $target, bool $overwrite = false)

Renames a file or a directory.

static bool
isReadable(string $filename)

Tells whether a file exists and is readable.

static 
mkdir(string|array|Traversable $dirs, int $mode = 0777)

Creates a directory recursively.

static 
chmod(string|array|Traversable $files, int $mode, int $umask = 00, bool $recursive = false)

Change mode for an array of files or directories.

static 
chown(string|array|Traversable $files, string $user, bool $recursive = false)

Change the owner of an array of files or directories.

getIterator(string $srcDir, callable $filter)

No description

static bool
chmodDir(string $path, int $mode = 0664)

No description

static string
availableSpace(string $dir = '.')

No description

static string
countSpace(string $dir = '.')

No description

static int
pathModeInfo(string $file_path)

文件或目录权限检查函数

static array|bool
load(string $src, string $format = self::FORMAT_PHP)

No description

from ReadTrait
static array
loadPhp(string $file, bool $throwError = true)

load array data form file.

from ReadTrait
static array
loadJson(string $file)

No description

from ReadTrait
static array|bool
loadIni(string $ini)

No description

from ReadTrait
static array|bool
loadYml(string $yml)

No description

from ReadTrait
static array|string
readAllLine($file, bool|true $filter = true)

No description

from ReadTrait
static array
readLines(string $fileName, int $startLine = 1, int $endLine = 10, string $mode = 'rb')

getLines 获取文件一定范围内的内容

from ReadTrait
static array
readSymmetry(string $fileName, integer $current = 1, integer $lineNum = 3)

symmetry 得到当前行对称上下几($lineNum)行的内容

from ReadTrait
static array
readRangeLines(string $file, int $baseLine, int $prevLines = 3, int $nextLines = 3)

No description

from ReadTrait
static array
getLines5u3d(string $file, int $baseLine = 1)

得到基准行数上5行下3行的内容, lines up and down

from ReadTrait
static array
tail(resource $fp, int $n, int $base = 5)

读取文件的最后几行(支持大文件读取)

from ReadTrait
static string
getName(string $file, bool $clearExt = false)

获得文件名称

static string
getSuffix($filename, bool $clearPoint = false)

获得文件扩展名、后缀名

static string
getExtension($path, bool $clearPoint = false)

获得文件扩展名、后缀名

static string
mimeType(string $file)

No description

static array
info(string $filename, bool $check = true)

No description

static array
getStat($filename)

No description

static bool
save(string $filename, string $data)

save description

static 
write($content, $path)

No description

static resource
openHandler(string $path)

No description

static 
writeToFile(resource $handler, string $content, string $path = '')

Attempts to write $content to the file specified by $handler. $path is used for printing exceptions.

static 
createAndWrite(array $fileData = [], $append = false, $mode = 0664)

********************** 创建多级目录和多个文件 ********************** 结合上两个函数

static bool|mixed|string
getContents(string $file, bool|false $useIncludePath = false, null|resource $streamContext = null, int $curlTimeout = 5)

No description

static 
move(string $file, string $target)

No description

static bool
delete($filename)

No description

static bool|int
copy($source, $destination, null $streamContext = null)

No description

static mixed
combine($inFile, $outFile)

No description

static string
stripPhpCode(string $source)

Removes whitespace from a PHP source string while preserving line numbers.

static 
downBigFile(string $file, string $as)

If you want to download files from a linux server with a filesize bigger than 2GB you can use the following

Details

in FileSystem at line 27
static bool isAbsPath(string $path)

Parameters

string $path

Return Value

bool

in FileSystem at line 49
static bool isAbsolutePath(string $file)

Returns whether the file path is an absolute path.

Parameters

string $file A file path

Return Value

bool

in FileSystem at line 64
static string pathFormat(string $dirName)

转换为标准的路径结构

Parameters

string $dirName

Return Value

string

in FileSystem at line 75
string clearPharPath(string $path)

Parameters

string $path e.g phar://E:/workenv/php-dockerized/www/phplang/ugirls-social/social-uem/uem.phar/web

Return Value

string

in FileSystem at line 94
static array|string exists(string $file, null|string $type = null)

检查文件/夹/链接是否存在

Parameters

string $file 要检查的目标
null|string $type

Return Value

array|string

in FileSystem at line 119
static check(string $file, null|string|array $ext = null)

Parameters

string $file
null|string|array $ext eg: 'jpg|gif'

Exceptions

FileNotFoundException
InvalidArgumentException

in FileSystem at line 145
static rename(string $origin, string $target, bool $overwrite = false)

Renames a file or a directory.

Parameters

string $origin The origin filename or directory
string $target The new filename or directory
bool $overwrite Whether to overwrite the target if it already exists

Exceptions

IOException When target file or directory already exists
IOException When origin cannot be renamed

in FileSystem at line 164
static bool isReadable(string $filename)

Tells whether a file exists and is readable.

Parameters

string $filename Path to the file

Return Value

bool

Exceptions

IOException When windows path is longer than 258 characters

in FileSystem at line 179
static mkdir(string|array|Traversable $dirs, int $mode = 0777)

Creates a directory recursively.

Parameters

string|array|Traversable $dirs The directory path
int $mode The directory mode

Exceptions

IOException On any directory creation failure

in FileSystem at line 210
static chmod(string|array|Traversable $files, int $mode, int $umask = 00, bool $recursive = false)

Change mode for an array of files or directories.

Parameters

string|array|Traversable $files A filename, an array of files, or a \Traversable instance to change mode
int $mode The new mode (octal)
int $umask The mode mask (octal)
bool $recursive Whether change the mod recursively or not

Exceptions

IOException When the change fail

in FileSystem at line 231
static chown(string|array|Traversable $files, string $user, bool $recursive = false)

Change the owner of an array of files or directories.

Parameters

string|array|Traversable $files A filename, an array of files, or a \Traversable instance to change owner
string $user The new owner user name
bool $recursive Whether change the owner recursively or not

Exceptions

IOException When the change fail

in FileSystem at line 255
static RecursiveIteratorIterator getIterator(string $srcDir, callable $filter)

Parameters

string $srcDir
callable $filter

Return Value

RecursiveIteratorIterator

in FileSystem at line 272
static bool chmodDir(string $path, int $mode = 0664)

Parameters

string $path
int $mode

Return Value

bool

in FileSystem at line 305
static string availableSpace(string $dir = '.')

Parameters

string $dir

Return Value

string

in FileSystem at line 322
static string countSpace(string $dir = '.')

Parameters

string $dir

Return Value

string

in FileSystem at line 342
static int pathModeInfo(string $file_path)

文件或目录权限检查函数

Parameters

string $file_path 文件路径

Return Value

int 返回值的取值范围为{0 <= x <= 15},每个值表示的含义可由四位二进制数组合推出。 返回值在二进制计数法中,四位由高到低分别代表 可执行rename()函数权限 |可对文件追加内容权限 |可写入文件权限|可读取文件权限。

in ReadTrait at line 31
static array|bool load(string $src, string $format = self::FORMAT_PHP)

Parameters

string $src 要解析的 文件 或 字符串内容。
string $format

Return Value

array|bool

Exceptions

FileNotFoundException

in ReadTrait at line 64
static array loadPhp(string $file, bool $throwError = true)

load array data form file.

Parameters

string $file
bool $throwError

Return Value

array

Exceptions

FileNotFoundException

in ReadTrait at line 85
static array loadJson(string $file)

Parameters

string $file

Return Value

array

in ReadTrait at line 94
static array|bool loadIni(string $ini)

Parameters

string $ini 要解析的 ini 文件名 或 字符串内容。

Return Value

array|bool

in ReadTrait at line 103
static array|bool loadYml(string $yml)

Parameters

string $yml 要解析的 yml 文件名 或 字符串内容。

Return Value

array|bool

in ReadTrait at line 115
static array|string readAllLine($file, bool|true $filter = true)

Parameters

$file
bool|true $filter

Return Value

array|string

Exceptions

FileNotFoundException
FileReadException

in ReadTrait at line 137
static array readLines(string $fileName, int $startLine = 1, int $endLine = 10, string $mode = 'rb')

getLines 获取文件一定范围内的内容

Parameters

string $fileName 含完整路径的文件
int $startLine 开始行数 默认第1行
int $endLine 结束行数 默认第50行
string $mode 打开文件方式

Return Value

array 返回内容

Exceptions

FileSystemException

in ReadTrait at line 191
static array readSymmetry(string $fileName, integer $current = 1, integer $lineNum = 3)

symmetry 得到当前行对称上下几($lineNum)行的内容

Parameters

string $fileName 含完整路径的文件
integer $current [当前行数]
integer $lineNum [获取行数] = $lineNum*2+1

Return Value

array

Exceptions

FileSystemException

in ReadTrait at line 212
static array readRangeLines(string $file, int $baseLine, int $prevLines = 3, int $nextLines = 3)

Parameters

string $file
int $baseLine
int $prevLines
int $nextLines

Return Value

array

Exceptions

FileSystemException

in ReadTrait at line 227
static array getLines5u3d(string $file, int $baseLine = 1)

得到基准行数上5行下3行的内容, lines up and down

Parameters

string $file
int $baseLine 基准行数

Return Value

array

Exceptions

FileSystemException

in ReadTrait at line 240
static array tail(resource $fp, int $n, int $base = 5)

读取文件的最后几行(支持大文件读取)

Parameters

resource $fp e.g fopen("access.log", "r+")
int $n
int $base

Return Value

array

at line 38
static string getName(string $file, bool $clearExt = false)

获得文件名称

Parameters

string $file
bool $clearExt 是否去掉文件名中的后缀,仅保留名字

Return Value

string

at line 51
static string getSuffix($filename, bool $clearPoint = false)

获得文件扩展名、后缀名

Parameters

$filename
bool $clearPoint 是否带点

Return Value

string

at line 64
static string getExtension($path, bool $clearPoint = false)

获得文件扩展名、后缀名

Parameters

$path
bool $clearPoint 是否带点

Return Value

string

at line 75
static string mimeType(string $file)

Parameters

string $file

Return Value

string eg: image/gif

at line 87
static array info(string $filename, bool $check = true)

Parameters

string $filename
bool $check

Return Value

array

Exceptions

FileNotFoundException
InvalidArgumentException

at line 106
static array getStat($filename)

Parameters

$filename

Return Value

array

at line 117
static bool save(string $filename, string $data)

save description

Parameters

string $filename
string $data

Return Value

bool

at line 127
static write($content, $path)

Parameters

$content
$path

Exceptions

IOException

at line 141
static resource openHandler(string $path)

Parameters

string $path

Return Value

resource

Exceptions

IOException

at line 157
static writeToFile(resource $handler, string $content, string $path = '')

Attempts to write $content to the file specified by $handler. $path is used for printing exceptions.

Parameters

resource $handler The resource to write to.
string $content The content to write.
string $path The path to the file (for exception printing only).

Exceptions

IOException

at line 175
static createAndWrite(array $fileData = [], $append = false, $mode = 0664)

********************** 创建多级目录和多个文件 ********************** 结合上两个函数

Parameters

array $fileData
  • 数组:要创建的多个文件名组成,含文件的完整路径
$append
  • 是否以追加的方式写入数据 默认false
$mode =0777 - 权限,默认0775 eg: $fileData = array( 'file_name' => 'content', 'case.html' => 'content' , );

at line 203
static bool|mixed|string getContents(string $file, bool|false $useIncludePath = false, null|resource $streamContext = null, int $curlTimeout = 5)

Parameters

string $file a file path or url path
bool|false $useIncludePath
null|resource $streamContext
int $curlTimeout

Return Value

bool|mixed|string

Exceptions

FileNotFoundException
FileReadException

at line 261
static move(string $file, string $target)

Parameters

string $file
string $target

Exceptions

FileNotFoundException
FileSystemException
IOException

at line 276
static bool delete($filename)

Parameters

$filename

Return Value

bool

Exceptions

InvalidArgumentException
FileNotFoundException

at line 289
static bool|int copy($source, $destination, null $streamContext = null)

Parameters

$source
$destination
null $streamContext

Return Value

bool|int

Exceptions

FileSystemException
FileNotFoundException

at line 309
static mixed combine($inFile, $outFile)

Parameters

$inFile
$outFile

Return Value

mixed

Exceptions

InvalidArgumentException
FileNotFoundException

at line 353
static string stripPhpCode(string $source)

Removes whitespace from a PHP source string while preserving line numbers.

Parameters

string $source A PHP string

Return Value

string The PHP string with the whitespace removed

at line 387
static downBigFile(string $file, string $as)

If you want to download files from a linux server with a filesize bigger than 2GB you can use the following

Parameters

string $file
string $as