The filesystem functions enable you to access and modify the filesystem.
The filesystem functions are built into the PHP core, so no extra installation is needed to use them.
On Unix platforms, a forward slash (/) is used as the directory separator.
On Windows platforms, both forward slashes (/) and backslashes () are acceptable as directory separators.
The behavior of filesystem functions can be influenced by settings in the php.ini
configuration file.
Name |
Default |
Description |
Changeable |
allow_url_fopen |
“1” |
Enables |
PHP_INI_SYSTEM |
allow_url_include |
“0” |
(available starting from PHP 5.2) |
PHP_INI_SYSTEM |
user_agent |
NULL |
Specifies the user agent that PHP should use when sending requests (available since PHP 4.3). |
PHP_INI_ALL |
default_socket_timeout |
“60” |
Sets the default timeout, in seconds, for socket-based streams (available since PHP 4.3). |
PHP_INI_ALL |
from |
“” |
Specifies the email address to use for unauthenticated FTP connections and in the |
PHP_INI_ALL |
auto_detect_line_endings |
“0” |
When set to “1”, PHP will check the data read by |
PHP_INI_ALL |
sys_temp_dir |
“” |
(available starting from PHP 5.5) |
PHP_INI_SYSTEM |
Function |
Description |
basename() |
Returns the filename part of a path. |
chgrp() |
Modifies the file’s group. |
chmod() |
Modifies the file’s mode. |
chown() |
Updates the file owner. |
clearstatcache() |
Clears the file status cache. |
copy() |
Duplicates a file. |
delete() |
Refer to |
dirname() |
Returns the directory name part of a path. |
disk_free_space() |
Returns the available space on a filesystem or disk. |
disk_total_space() |
Returns the total capacity of a filesystem or disk. |
diskfreespace() |
An alias for |
fclose() |
Closes an open file. |
feof() |
Checks if the end-of-file (EOF) has been reached for an open file. |
fflush() |
Flushes buffered output to an open file. |
fgetc() |
Returns a single character from an open file. |
fgetcsv() |
Returns a line from an open CSV file. |
fgets() |
Returns a line from an open file. |
fgetss() |
Deprecated as of PHP 7.3. Returns a line from an open file with HTML and PHP tags removed. |
file() |
Reads the contents of a file into an array. |
file_exists() |
Checks if a file or directory exists. |
file_get_contents() |
Reads the contents of a file into a string. |
file_put_contents() |
Writes data to a file. |
fileatime() |
Returns the last access time of a file. |
filectime() |
Returns the last modification time of a file. |
filegroup() |
Returns the group ID associated with a file. |
fileinode() |
Returns the inode number of a file. |
filemtime() |
Returns the last modification time of a file. |
fileowner() |
Returns the user ID (owner) of a file. |
fileperms() |
Returns the permissions of the file. |
filesize() |
Returns the size of the file. |
filetype() |
Returns the type of the file. |
flock() |
Locks or unlocks a file. |
fnmatch() |
Compares a filename or string to a specified pattern. |
fopen() |
Opens a file or URL. |
fpassthru() |
Reads from the current position in a file until EOF and writes the output to the buffer. |
fputcsv() |
Formats a line as CSV and writes it to an open file. |
fputs() |
A synonym for |
fread() |
Reads from an open file in a binary-safe manner. |
fscanf() |
Parses input from an open file based on a specified format. |
fseek() |
Moves the file pointer to a specified position in an open file. |
fstat() |
Provides details about an open file. |
ftell() |
Returns the current position of the file pointer in an open file. |
ftruncate() |
Truncates an open file to a specified length. |
fwrite() |
Writes to an open file in a binary-safe manner. |
glob() |
Returns an array of filenames or directories that match a specified pattern. |
is_dir() |
Checks if a file is a directory. |
is_executable() |
Checks if a file is executable. |
is_file() |
Checks if a file is a regular file. |
is_link() |
Checks if a file is a symbolic link. |
is_readable() |
Checks if a file is readable. |
is_uploaded_file() |
Checks if a file was uploaded through an HTTP POST request. |
is_writable() |
Checks if a file is writable. |
is_writeable() |
A synonym for |
lchgrp() |
Changes the user ownership of a symbolic link. |
lchown() |
Changes the user ownership of a symbolic link. |
link() |
Creates a hard link. |
linkinfo() |
Returns details about a hard link. |
lstat() |
Returns details 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 details about a file path. |
pclose() |
Closes a pipe that was opened with |
popen() |
Opens a pipe. |
readfile() |
Reads a file and outputs its contents to the buffer. |
readlink() |
Returns the target path of a symbolic link. |
realpath() |
Returns the absolute pathname. |
realpath_cache_get() |
Returns entries from the realpath cache. |
realpath_cache_size() |
Returns the size of the realpath cache. |
rename() |
Renames a file or directory. |
rewind() |
Resets a file pointer to the beginning of the file. |
rmdir() |
Deletes an empty directory. |
set_file_buffer() |
A synonym for |
stat() |
Returns details about a file. |
symlink() |
Creates a symbolic link. |
tempnam() |
Creates a unique temporary file. |
tmpfile() |
Generates a unique temporary file. |
touch() |
Sets the access and modification times of a file. |
umask() |
Changes file permissions for files. |
unlink() |
Deletes a file. |