PHP 5 FilesystemFunctions


PHP Filesystem Introduction

Filesystem functions allow you to access and manipulate the file system.


Installation

Filesystem functions are part of the PHP core. There is no installation needed to use these functions.


Runtime Configuration

The behavior of Filesystem functions is affected by settings in php.ini.

Filesystem configuration options:

Name Default Description Changeable
allow_url_fopen "1" Allows fopen()-type functions to use URLs. (Available since PHP 4.0.4) PHP_INI_SYSTEM
user_agent NULL Defines the user agent that PHP sends. (Available since PHP 4.3) PHP_INI_ALL
default_socket_timeout "60" Sets the default timeout time (in seconds) for socket-based streams. (Available since PHP 4.3) PHP_INI_ALL
from "" Defines the password for anonymous FTP (your email address). PHP_INI_ALL
auto_detect_line_endings "0" When set to "1", PHP will check whether the line-ending characters in data obtained via fgets() and file() conform to Unix, MS-DOS, or Mac conventions. (Available since PHP 4.3) PHP_INI_ALL


Unix / Windows Compatibility

When specifying a path on Unix platforms, the forward slash (/) is used as the directory separator. On Windows platforms, both the forward slash (/) and the backslash (\) can be used.


PHP 5 Filesystem Functions

Function Description
basename() Returns the filename component of a path.
chgrp() Changes the file group.
chmod() Changes the file mode.
chown() Changes the file owner.
clearstatcache() Clears the file status cache.
copy() Copies a file.
delete() See also unlink() or unset()
dirname() Returns the directory name component of a path.
disk_free_space() Returns the available space in a directory.
disk_total_space() Returns the total disk capacity of a directory.
diskfreespace() Alias of disk_free_space().
fclose() Closes an open file.
feof() Tests whether the file pointer is at the end of the file.
fflush() Flushes buffered output to an open file.
fgetc() Returns a character from an open file.
fgetcsv() Parses a line from an open file, verifyingCSV fields。
fgets() Returns a line from an open file.
fgetss() Returns a line from an open file, stripping HTML and PHP tags.
file() Reads a file into an array.
file_exists() Checks whether a file or directory exists.
file_get_contents() Reads a file into a string.
file_put_contents() Writes a string to a file.
fileatime() Returns the last access time of a file.
filectime() Returns the last modified time of a file.
filegroup() Returns the group ID of a file.
fileinode() Returns the inode number of a file.
filemtime() Returns the last modified time of the file content.
fileowner() Returns the user ID (owner) of a file.
fileperms() Returns the file permissions.
filesize() Returns the file size.
filetype() Returns the file type.
flock() Locks or releases a file.
fnmatch() Matches a filename or string against a specified pattern.
fopen() Opens a file or URL.
fpassthru() Reads data from an open file until end-of-file (EOF) and writes the result to the output buffer.
fputcsv() Formats a line as CSV and writes it to an open file.
fputs() Alias of fwrite().
fread() Reads an open file.
fscanf() Parses input according to a specified format.
fseek() Seeks in an open file.
fstat() Returns information about an open file.
ftell() Returns the current position in an open file.
ftruncate() Truncates an open file to the specified length.
fwrite() Writes to an open file.
glob() Returns an array containing filenames/directories that match a specified pattern.
is_dir() Determines whether a file is a directory.
is_executable() Determines whether a file is executable.
is_file() Determines whether a file is a regular file.
is_link() Determines whether a file is a link.
is_readable() Determines whether a file is readable.
is_uploaded_file() Determines whether a file is uploaded via HTTP POST.
is_writable() Determines whether a file is writable.
is_writeable() Alias of is_writable().
lchgrp() Changes the group ownership of a symbolic link.
lchown() Changes the user ownership of a symbolic link.
link() Creates a hard link.
linkinfo() Returns information about a hard link.
lstat() Returns information about a file or symbolic link.
mkdir() Creates a directory.
move_uploaded_file() Moves an uploaded file to a new location.
parse_ini_file() Parses a configuration file.
parse_ini_string() Parses a configuration string.
pathinfo() Returns information about a file path.
pclose() Closes a process opened by popen().
popen() Opens a process.
readfile() Reads a file and writes it to the output buffer.
readlink() Returns the target of a symbolic link.
realpath() Returns the absolute pathname.
realpath_cache_get() Returns cache entries.
realpath_cache_size() Returns the cache size.
rename() Renames a file or directory.
rewind() Rewinds the position of a file pointer.
rmdir() Removes an empty directory.
set_file_buffer() Sets the buffer size of an open file.
stat() Returns information about a file.
symlink() Creates a symbolic link.
tempnam() Creates a unique temporary file.
tmpfile() Creates a unique temporary file.
touch() Sets the access and modification time of a file.
umask() Changes the file permissions.
unlink() Deletes a file.
Other Extensions