zoukankan      html  css  js  c++  java
  • 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用于对临时文件操作

  • 相关阅读:
    浅谈我对几个Web前端开发框架的比较
    国内最火的五款HTML5前端开发框架
    比较JSF、Spring MVC、Stripes、Struts 2、Tapestry、Wicket
    请问实现MVC的框架有哪些,实现持久化操作的框架有哪些,还有类似于spring整合的框架又有哪些
    Guice与Spring框架的区别
    致Play Framework开发者们的一封信
    有可能挑战Java优势的四种技术
    大家所说的full-stack框架到底是指什么?
    db_table--Spring Security3.1 最新配置实例
    JEECG平台JWT接口文档
  • 原文地址:https://www.cnblogs.com/scarecrowlxb/p/6536655.html
Copyright © 2011-2022 走看看