spl之文件处理

spl是php标准库的缩写

spl文件处理类库: SplFileInfo  //是一个类用以获取文件的各种信息SplFileInfo的所有方法如下

      方法名            - ---   说明
2. getATime( ) : --- Gets last access time of the file
3. getBasename( ) : --- Gets the base name of the file
4. getCTime( ) : --- 获取文件 inode 修改时间
5. getExtension( ) : --- Gets the file extension
6. getFileInfo( ) : --- Gets an SplFileInfo object for the file
7. getFilename( ) : --- Gets the filename
8. getGroup( ) : --- Gets the file group
9. getInode( ) : --- Gets the inode for the file
10. getLinkTarget( ) : --- Gets the target of a link
11. getMTime( ) : --- Gets the last modified time
12. getOwner( ) : --- Gets the owner of the file
13. getPath( ) : --- Gets the path without filename
14. getPathInfo( ) : --- Gets an SplFileInfo object for the path
15. getPathname( ) : --- Gets the path to the file
16. getPerms( ) : --- Gets file permissions
17. getRealPath( ) : --- Gets absolute path to file
18. getSize( ) : --- Gets file size
19. getType( ) : --- Gets file type
20. isDir( ) : --- Tells if the file is a directory
21. isExecutable( ) : --- Tells if the file is executable
22. isFile( ) : --- Tells if the object references a regular file
23. isLink( ) : --- Tells if the file is a link
24. isReadable( ) : --- Tells if file is readable
25. isWritable( ) : --- Tells if the entry is writable
26. openFile( ) : --- Gets an SplFileObject object for the file
27. setFileClass( ) : --- Sets the class used with openFile
28. setInfoClass( ) : --- Sets the class used with getFileInfo and getPathInfo
29. __toString( ) : --- Returns the path to the file as a string

      如获取index.php的相关信息 的代码:

<?php
/*
 *author:稻草人
 *email:2282152858@qq.com
 *cnblogs: http://cnblogs.com/scarecrowlxb
 *create time :2017/3/11 23:14
 */
//获取文件信息
$file = new SplFileInfo("./index.php");
echo '创建时间:'.$file->getCTime().PHP_EOL;
echo '修改时间:'.$file->getMTime().PHP_EOL;
echo '文件大小:'.$file->getSize().PHP_EOL;
echo '文件名:'.$file->getFileName().PHP_EOL;

//读取文件内容
$fileobj = $file->openFile("r");
while($fileobj->valid()){
	//valid 是当读取到的内容无效时返回false
	echo $fileobj->fgets();
}

  

具体见php参考手册中  函数参考->其他基本扩展->spl->文件处理

还有两个类:SplFileObject 和SplTempFileObject

SplFileObject 类继承了SplFileInfo 并实现文件的遍历查找操作

SplTempFileObject类继承了SplFileObject用于对临时文件操作

 

转载于:https://www.cnblogs.com/scarecrowlxb/p/6536655.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值