spl_object_hash
SplFileInfo
SPL
PHP Manual

# File Handling

Table of Contents

- SplFileInfo — The SplFileInfo class
  - SplFileInfo::__construct — Construct a new SplFileInfo object
  - SplFileInfo::getATime — Gets last access time of the file
  - SplFileInfo::getBasename — Gets the base name of the file
  - SplFileInfo::getCTime — Gets the inode change time
  - SplFileInfo::getExtension — Gets the file extension
  - SplFileInfo::getFileInfo — Gets an SplFileInfo object for the file
  - SplFileInfo::getFilename — Gets the filename
  - SplFileInfo::getGroup — Gets the file group
  - SplFileInfo::getInode — Gets the inode for the file
  - SplFileInfo::getLinkTarget — Gets the target of a link
  - SplFileInfo::getMTime — Gets the last modified time
  - SplFileInfo::getOwner — Gets the owner of the file
  - SplFileInfo::getPath — Gets the path without filename
  - SplFileInfo::getPathInfo — Gets an SplFileInfo object for the path
  - SplFileInfo::getPathname — Gets the path to the file
  - SplFileInfo::getPerms — Gets file permissions
  - SplFileInfo::getRealPath — Gets absolute path to file
  - SplFileInfo::getSize — Gets file size
  - SplFileInfo::getType — Gets file type
  - SplFileInfo::isDir — Tells if the file is a directory
  - SplFileInfo::isExecutable — Tells if the file is executable
  - SplFileInfo::isFile — Tells if the object references a regular file
  - SplFileInfo::isLink — Tells if the file is a link
  - SplFileInfo::isReadable — Tells if file is readable
  - SplFileInfo::isWritable — Tells if the entry is writable
  - SplFileInfo::openFile — Gets an SplFileObject object for the file
  - SplFileInfo::setFileClass — Sets the class name used with SplFileInfo::openFile
  - SplFileInfo::setInfoClass — Sets the class used with getFileInfo and getPathInfo
  - SplFileInfo::__toString — Returns the path to the file as a string
- SplFileObject — The SplFileObject class
  - SplFileObject::__construct — Construct a new file object.
  - SplFileObject::current — Retrieve current line of file
  - SplFileObject::eof — Reached end of file
  - SplFileObject::fflush — Flushes the output to the file
  - SplFileObject::fgetc — Gets character from file
  - SplFileObject::fgetcsv — Gets line from file and parse as CSV fields
  - SplFileObject::fgets — Gets line from file
  - SplFileObject::fgetss — Gets line from file and strip HTML tags
  - SplFileObject::flock — Portable file locking
  - SplFileObject::fpassthru — Output all remaining data on a file pointer
  - SplFileObject::fputcsv — Write a field array as a CSV line
  - SplFileObject::fscanf — Parses input from file according to a format
  - SplFileObject::fseek — Seek to a position
  - SplFileObject::fstat — Gets information about the file
  - SplFileObject::ftell — Return current file position
  - SplFileObject::ftruncate — Truncates the file to a given length
  - SplFileObject::fwrite — Write to file
  - SplFileObject::getChildren — No purpose
  - SplFileObject::getCsvControl — Get the delimiter and enclosure character for CSV
  - SplFileObject::getCurrentLine — Alias of SplFileObject::fgets
  - SplFileObject::getFlags — Gets flags for the SplFileObject
  - SplFileObject::getMaxLineLen — Get maximum line length
  - SplFileObject::hasChildren — SplFileObject does not have children
  - SplFileObject::key — Get line number
  - SplFileObject::next — Read next line
  - SplFileObject::rewind — Rewind the file to the first line
  - SplFileObject::seek — Seek to specified line
  - SplFileObject::setCsvControl — Set the delimiter and enclosure character for CSV
  - SplFileObject::setFlags — Sets flags for the SplFileObject
  - SplFileObject::setMaxLineLen — Set maximum line length
  - SplFileObject::__toString — Alias of SplFileObject::current
  - SplFileObject::valid — Not at EOF
- SplTempFileObject — The SplTempFileObject class
  - SplTempFileObject::__construct — Construct a new temporary file object

SPL provides a number of classes to work with files.

# The SplFileInfo class

## Introduction

The SplFileInfo class offers a high-level object oriented interface to information for an individual file.

## Class synopsis

SplFileInfo
class SplFileInfo {
/* Methods */
public __construct ( string `$file_name` )
public int getATime ( void )
public string getBasename ([ string `$suffix` ] )
public int getCTime ( void )
public string getExtension ( void )
public SplFileInfo getFileInfo ([ string `$class_name` ] )
public string getFilename ( void )
public int getGroup ( void )
public int getInode ( void )
public string getLinkTarget ( void )
public int getMTime ( void )
public int getOwner ( void )
public string getPath ( void )
public SplFileInfo getPathInfo ([ string `$class_name` ] )
public string getPathname ( void )
public int getPerms ( void )
public string getRealPath ( void )
public int getSize ( void )
public string getType ( void )
public bool isDir ( void )
public bool isExecutable ( void )
public bool isFile ( void )
public bool isLink ( void )
public bool isReadable ( void )
public bool isWritable ( void )
public SplFileObject openFile ([ string `$open_mode` = r [, bool `$use_include_path` = false [, resource `$context` = `NULL` ]]] )
public void setFileClass ([ string `$class_name` ] )
public void setInfoClass ([ string `$class_name` ] )
public void __toString ( void )
}

# The SplFileObject class

## Introduction

The SplFileObject class offers an object oriented interface for a file.

## Class synopsis

SplFileObject
class SplFileObject extends SplFileInfo implements RecursiveIterator , SeekableIterator {
/* Constants */
const integer SplFileObject::DROP_NEW_LINE = 1 ;
const integer SplFileObject::READ_AHEAD = 2 ;
const integer SplFileObject::SKIP_EMPTY = 4 ;
const integer SplFileObject::READ_CSV = 8 ;
/* Methods */
public __construct ( string `$filename` [, string `$open_mode` = "r" [, bool `$use_include_path` = false [, resource `$context` ]]] )
public string|array current ( void )
public bool eof ( void )
public bool fflush ( void )
public string fgetc ( void )
public array fgetcsv ([ string `$delimiter` = "," [, string `$enclosure` = "\"" [, string `$escape` = "\\" ]]] )
public string fgets ( void )
public string fgetss ([ string `$allowable_tags` ] )
public bool flock ( int `$operation` [, int `&$wouldblock` ] )
public int fpassthru ( void )
public int fputcsv ( array `$fields` [, string `$delimiter` = ',' [, string `$enclosure` = '"' ]] )
public mixed fscanf ( string `$format` [, mixed `&$...` ] )
public int fseek ( int `$offset` [, int `$whence` = SEEK_SET ] )
public array fstat ( void )
public int ftell ( void )
public bool ftruncate ( int `$size` )
public int fwrite ( string `$str` [, int `$length` ] )
public void getChildren ( void )
public array getCsvControl ( void )
public int getFlags ( void )
public int getMaxLineLen ( void )
public bool hasChildren ( void )
public int key ( void )
public void next ( void )
public void rewind ( void )
public void seek ( int `$line_pos` )
public void setCsvControl ([ string `$delimiter` = "," [, string `$enclosure` = "\"" [, string `$escape` = "\\" ]]] )
public void setFlags ( int `$flags` )
public void setMaxLineLen ( int `$max_len` )
public void __toString ( void )
public bool valid ( void )
/* Inherited methods */
public SplFileInfo::__construct ( string `$file_name` )
public int SplFileInfo::getATime ( void )
public string SplFileInfo::getBasename ([ string `$suffix` ] )
public int SplFileInfo::getCTime ( void )
public string SplFileInfo::getExtension ( void )
public SplFileInfo SplFileInfo::getFileInfo ([ string `$class_name` ] )
public string SplFileInfo::getFilename ( void )
public int SplFileInfo::getGroup ( void )
public int SplFileInfo::getInode ( void )
public string SplFileInfo::getLinkTarget ( void )
public int SplFileInfo::getMTime ( void )
public int SplFileInfo::getOwner ( void )
public string SplFileInfo::getPath ( void )
public SplFileInfo SplFileInfo::getPathInfo ([ string `$class_name` ] )
public string SplFileInfo::getPathname ( void )
public int SplFileInfo::getPerms ( void )
public string SplFileInfo::getRealPath ( void )
public int SplFileInfo::getSize ( void )
public string SplFileInfo::getType ( void )
public bool SplFileInfo::isDir ( void )
public bool SplFileInfo::isExecutable ( void )
public bool SplFileInfo::isFile ( void )
public bool SplFileInfo::isLink ( void )
public bool SplFileInfo::isReadable ( void )
public bool SplFileInfo::isWritable ( void )
public SplFileObject SplFileInfo::openFile ([ string `$open_mode` = r [, bool `$use_include_path` = false [, resource `$context` = `NULL` ]]] )
public void SplFileInfo::setFileClass ([ string `$class_name` ] )
public void SplFileInfo::setInfoClass ([ string `$class_name` ] )
public void SplFileInfo::__toString ( void )
}

## Predefined Constants

`SplFileObject::DROP_NEW_LINE`

  Drop newlines at the end of a line.

`SplFileObject::READ_AHEAD`

  Read on rewind/next.

`SplFileObject::SKIP_EMPTY`

  Skips empty lines in the file. This requires the `READ_AHEAD` flag be enabled, to work as expected.

`SplFileObject::READ_CSV`

  Read lines as CSV rows.

## Changelog

Version | Description
--- | ---
5.3.9 | `SplFileObject::SKIP_EMPTY` value changed to 4. Previously, value was 6.

# The SplTempFileObject class

## Introduction

The SplTempFileObject class offers an object oriented interface for a temporary file.

## Class synopsis

SplTempFileObject
class SplTempFileObject extends SplFileObject implements SeekableIterator , RecursiveIterator {
/* Methods */
public __construct ([ int `$max_memory` ] )
/* Inherited methods */
public SplFileObject::__construct ( string `$filename` [, string `$open_mode` = "r" [, bool `$use_include_path` = false [, resource `$context` ]]] )
public string|array SplFileObject::current ( void )
public bool SplFileObject::eof ( void )
public bool SplFileObject::fflush ( void )
public string SplFileObject::fgetc ( void )
public array SplFileObject::fgetcsv ([ string `$delimiter` = "," [, string `$enclosure` = "\"" [, string `$escape` = "\\" ]]] )
public string SplFileObject::fgets ( void )
public string SplFileObject::fgetss ([ string `$allowable_tags` ] )
public bool SplFileObject::flock ( int `$operation` [, int `&$wouldblock` ] )
public int SplFileObject::fpassthru ( void )
public int SplFileObject::fputcsv ( array `$fields` [, string `$delimiter` = ',' [, string `$enclosure` = '"' ]] )
public mixed SplFileObject::fscanf ( string `$format` [, mixed `&$...` ] )
public int SplFileObject::fseek ( int `$offset` [, int `$whence` = SEEK_SET ] )
public array SplFileObject::fstat ( void )
public int SplFileObject::ftell ( void )
public bool SplFileObject::ftruncate ( int `$size` )
public int SplFileObject::fwrite ( string `$str` [, int `$length` ] )
public void SplFileObject::getChildren ( void )
public array SplFileObject::getCsvControl ( void )
public int SplFileObject::getFlags ( void )
public int SplFileObject::getMaxLineLen ( void )
public bool SplFileObject::hasChildren ( void )
public int SplFileObject::key ( void )
public void SplFileObject::next ( void )
public void SplFileObject::rewind ( void )
public void SplFileObject::seek ( int `$line_pos` )
public void SplFileObject::setCsvControl ([ string `$delimiter` = "," [, string `$enclosure` = "\"" [, string `$escape` = "\\" ]]] )
public void SplFileObject::setFlags ( int `$flags` )
public void SplFileObject::setMaxLineLen ( int `$max_len` )
public void SplFileObject::__toString ( void )
public bool SplFileObject::valid ( void )
}