PHP常用函数总结(180多个)

2019-05-02 07:19:53于丽

返回值: 如果打开失败,本函数返回 FALSE

117.fclose(): 关闭一个已打开的文件指针

 $handle = fopen('somefile.txt', 'r');
 fclose($handle);
 bool fclose(resource handle)


输出: 如果成功则返回 TRUE,失败则返回 FALSE

文件属性

118.file_exists(): 检查文件或目录是否存在

 $filename = '/path/to/foo.txt';
 if (file_exists($filename)) {
 echo "exists";
 } else {
 echo "does not exist";
 }

调用: bool file_exists ( string filename ) 输入: 指定的文件或目录 输出: 存在则返回 TRUE,否则返回 FALSE

119.filesize(): 取得文件大小

$filename = 'somefile.txt';
echo $filename . ': ' . filesize($filename) .'bytes';

调用: int filesize ( string $filename )

输出: 返回文件大小的字节数,如果出错返回 FALSE 并生成一条 E_WARNING 级的错误

120.is_readable(): 判断给定文件是否可读

 $filename = 'test.txt';
 if (is_readable($filename)) {
 echo '可读';
 } else {
 echo '不可读';
 }

调用: bool is_readable ( string $filename ) 输出: 如果由 filename指定的文件或目录存在并且可读则返回 TRUE

121.is_writable(): 判断给定文件是否可写

 $filename = 'test.txt';
 if (is_writable($filename)) {
 echo '可写';
 } else {
 echo '不可写';
 }

调用: bool is_writable ( string $filename ) filename 参数 可以是一个允许进行是否可写检查的目录名

输出: 如果文件存在并且可写则返回 TRUE。

122.is_executable(): 判断给定文件是否可执行

 $file = 'setup.exe';
 if (is_executable($file)) {
 echo '可执行';
 } else {
 echo '不可执行';
 }

调用: bool is_executable ( string $filename ) 输出: 如果文件存在且可执行则返回 TRUE

123.filectime(): 获取文件的创建时间

 

$filename = 'somefile.txt';
echo filectime($filename);

调用: int filectime ( string $filename ) 输出: 时间以 Unix 时间戳的方式返回,如果出错则返回FALSE

124.filemtime(): 获取文件的修改时间

$filename = 'somefile.txt';
echo filemtime($filename);

    int filemtime ( string $filename )
输出: 返回文件上次被修改的时间,出错时返回 FALSE。时间以 Unix时间戳的方式返回

125.fileatime(): 获取文件的上次访问时间

 $filename = 'somefile.txt';
echo fileatime($filename);

调用: int fileatime (string $filename)

输出: 返回文件上次被访问的时间, 如果出错则返回FALSE. 时间以Unix时间戳的方式返回.

126.stat(): 获取文件大部分属性值

$filename = 'somefile.txt';
var_dump(fileatime($filename));
相关文章 大家在看