首页 > 代码库 > spl之文件处理

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用于对临时文件操作

 

spl之文件处理