PHP - Filesystem Functions


The file system functions are used to access and manipulate the file system PHP provides you all the possible functions you may need to manipulate a file.


The error and logging functions are part of the PHP core. There is no installation needed to use these functions.

Runtime Configuration

The behaviour of these functions is affected by settings in php.ini.

Name Default Changeable Changelog
allow_url_fopen "1" PHP_INI_ALL PHP_INI_ALL in PHP <= 4.3.4. PHP_INI_SYSTEM in PHP < 6. Available since PHP 4.0.4.
allow_url_include "0" PHP_INI_ALL PHP_INI_SYSTEM in PHP 5. Available since PHP 5.2.0.
user_agent NULL PHP_INI_ALL Available since PHP 4.0.3.
default_socket_timeout "60" PHP_INI_ALL Available since PHP 4.3.0.
from "" PHP_INI_ALL
auto_detect_line_endings "0" PHP_INI_ALL Available since PHP 4.3.0.

PHP Error and Logging Constants

PHP − indicates the earliest version of PHP that supports the constant.

You can use any of the constant while configuring your php.ini file.

Constant Description PHP
FILE_USE_INCLUDE_PATH Search for filename in include_path 5.0.0
FILE_APPEND Append content to existing file.
FILE_IGNORE_NEW_LINES Strip EOL characters 5.0.0
FILE_SKIP_EMPTY_LINES Skip empty lines 5.0.0
FILE_BINARY Binary mode 6.0.0
FILE_TEXT Text mode 6.0.0

List of Functions

PHP − indicates the earliest version of PHP that supports the function.

Function Description PHP
basename() Returns filename component of path 3
chgrp() Changes file group 3
chmod() Changes file mode 3
chown() Changes file owner 3
clearstatcache() Clears file status cache 3
copy() Copies file 3
delete() Deletes file
dirname() Returns directory name component of path 3
disk_free_space() Returns available space in directory 4.0.7
disk_total_space() Returns the total size of a directory 4.0.7
diskfreespace() Alias of disk_free_space() 4.0.7
fclose() Closes an open file pointer 3
feof() Tests for end-of-file on a file pointer 3
fflush() Flushes the output to a file 4
fgetc() Gets character from file pointer 3
fgetcsv() Gets line from file pointer and parse for CSV fields 3
fgets() Gets line from file pointer 3
fgetss() Gets line from file pointer and strip HTML tags 3
file_exists() Checks whether a file or directory exists 3
file_get_contents() Reads entire file into a string 4.3.0
file_put_contents() Write a string to a file 5
file() Reads entire file into an array 3
fileatime() Gets last access time of file 3
filectime() Gets inode change time of file 3
filegroup() Gets file group 3