Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1
163

■ ■ ■


CHAPTER 11


SPL File and


Directory Handling


The SPL provides several classes and iterators that allow for object-oriented access of files and
directories. In this chapter, you will learn about how the traditional file-access functions of PHP
have been transitioned to object form.
Iteration plays an important role in working with files and folders. In this chapter, you will
be introduced to several advanced iteration techniques for listing, searching, and filtering files
and directories.
Finally, the SPL provides the ability to manipulate the content of files. It allows you to parse
INI files, search using regular expressions, read comma-separated value (CSV) data, and so on.
This chapter provides comprehensive examples of how to manipulate files in your applications.

File and Directory Information


The purpose of the SplFileInfo class is to provide object-oriented access to the properties of a
file or directory. It is defined as shown in Listing 11-1.

Listing 11-1. SplFileInfo Definition

class SplFileInfo {
function __construct($file_name) {}
function getPath() {}
function getFilename() {}
function getFileInfo(string class_name = NULL) {}
function getPathname() {}
function getPathInfo(string class_name = NULL) {}
function getPerms() {}
function getInode() {}
function getSize() {}
function getOwner() {}
function getGroup() {}
function getATime() {}

McArthur_819-9C11.fm Page 163 Thursday, February 28, 2008 7:49 AM

Free download pdf