The filesystem functions provide a wide range of tools to access and manipulate the filesystem.
OverviewPHP's filesystem functions provide a fairly broad range of functionality. All the standard functions that programmers expect are included - opening, reading, and writing files; querying the filesystem; changing permissions; copying and deleting files; etc. Many of these functions have been transparently extended to work with HTTP and FTP resources, allowing easy reading of remote files.
There are also a series of convenience functions like fgetcsv() , which parses CSV-format data while reading it from a file, and file() , which reads a file and then places it, line by line, into an array.
The group also includes some miscellaneous filesystem-related functions to generate names for temporary files ( tempnam() ) and open pipes to commands ( popen() ) . Note that most of the directory-related functions are documented in the Directory Functions module.
Configuring the Filesystem FunctionsThe following configuration directives can be used to control the behavior of the Filesystem functions.
| Directive Name | Value Type | Description |
|---|---|---|
| allow_url_fopen | boolean (on/off) |
Allow the fopen-type functions to work with URLs. i.e. $fp = fopen ('http://www.example.com', 'r');
NoteFor PHP 4.0.3 and below you must use the --disable-url-fopen-wrapper configure option to disable this feature. |
| include_path | string | The paths to search when attempting to include or require a file. Certain other functions, like fopen() , may use these paths as well. |
| magic_quotes_runtime | boolean (on/off) | If this directive is enabled, data received from many functions that retrieve data from external sources (such as the database and program execution functions), will be automatically processed with the addslashes() function. |
| magic_quotes_sybase | boolean (on/off) | If magic_quotes_sybase is enabled, then single quotes escaped by magic_quotes_gpc or magic_quotes_runtime are escaped with a leading single quote instead of a backslash; '' instead of \'. |
| open_basedir | string | If this directive is set, PHP only allows access to files that are in or below the directories specified. The paths can be absolute (like /home/user) or relative (such as . or public_html) and are separated by a colon under UNIX-like operating systems and a semicolon under Windows operating systems (/home/:.:/opt/php/shared/). |
Installing Filesystem SupportThese functions are built into PHP by default and can only be disabled by editing the source code and recompiling, or by using the disable_functions directive in php.ini.
Additional InformationFor more information, see:
The PHP Online Manual ( http://php.net/manual/)
Table of Contents