Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^164) CHAPTER 11 ■ SPL FILE AND DIRECTORY HANDLING
function getMTime() {}
function getCTime() {}
function getType() {}
function isWritable() {}
function isReadable() {}
function isExecutable() {}
function isFile() {}
function isDir() {}
function isLink() {}
function __toString() {}
function openFile($mode = 'r', $use_include_path = false, $context = NULL) {}
function setFileClass(string class_name = "SplFileObject") {}
function setInfoClass(string class_name = "SplFileInfo") {}
}
The typical usage of the SPLFileInfo class is to retrieve information about a file or folder.
Listing 11-2 shows a basic invocation.
Listing 11-2. Using SPLFileInfo
$fileName = '/path/to/file/filename.php';
$fileInfo = new SPLFileInfo($fileName);
$fileProps = array();
$fileProps['path'] = $fileInfo->getPath();
$fileProps['filename'] = $fileInfo->getFilename();
$fileProps['pathname'] = $fileInfo->getPathname();
$fileProps['perms'] = $fileInfo->getPerms();
$fileProps['inode'] = $fileInfo->getInode();
$fileProps['size'] = $fileInfo->getSize();
$fileProps['owner'] = $fileInfo->getOwner();
$fileProps['group'] = $fileInfo->getGroup();
$fileProps['atime'] = $fileInfo->getATime();
$fileProps['mtime'] = $fileInfo->getMTime();
$fileProps['ctime'] = $fileInfo->getCTime();
$fileProps['type'] = $fileInfo->getType();
$fileProps['isWritable'] = $fileInfo->isWritable();
$fileProps['isReadable'] = $fileInfo->isReadable();
$fileProps['isExecutable'] = $fileInfo->isExecutable();
$fileProps['isFile'] = $fileInfo->isFile();
$fileProps['isDir'] = $fileInfo->isDir();
$fileProps['isLink'] = $fileInfo->isLink();
var_export($fileProps);
McArthur_819-9C11.fm Page 164 Thursday, February 28, 2008 7:49 AM

Free download pdf