PHP Filesystem Functions
- Previous Page PHP Error
- Next Page PHP Filter
PHP Filesystem Introduction
Filesystem functions allow you to access and operate on the filesystem.
Installation
Filesystem functions are part of the core of PHP. These functions can be used without installation.
Runtime Configuration
The behavior of filesystem functions is affected by the settings in php.ini.
Filesystem Configuration Options:
Name | Default | Description | Changeable |
---|---|---|---|
allow_url_fopen | "1" |
This option activates the fopen wrapper protocol in URL format, allowing access to URL objects such as files. The default wrapper protocol provides access to remote files using ftp and http protocols, and some extension libraries such as zlib may register more wrapper protocols. (Available after PHP 4.0.4 version.) |
PHP_INI_SYSTEM |
user_agent | NULL |
Define the User-Agent sent by PHP. (Available since PHP 4.3.0 version.) |
PHP_INI_ALL |
default_socket_timeout | "60" |
Default timeout time (in seconds) for streams based on socket. (Available since PHP 4.3.0 version.) |
PHP_INI_ALL |
from | "" | Define the password for anonymous ftp (your email address). | PHP_INI_ALL |
auto_detect_line_endings | "0" |
When set to On, PHP will check if the line terminator in the data obtained through fgets() and file() is in line with Unix, MS-DOS, or Macintosh conventions. This makes PHP able to interact with Macintosh systems, but the default value is Off because there is a slight performance loss when detecting the first-line EOL habit, and people who use the carriage return symbol as a project separator in Unix systems may encounter downward-incompatible behavior. (Available since PHP 4.3.0 version.) |
PHP_INI_ALL |
Unix / Windows Compatibility
When specifying paths on Unix platforms, the forward slash (/) is used as a directory separator. On Windows platforms, both forward slash (/) and backslash (\) can be used.
PHP Filesystem Functions
PHP:Indicates the earliest PHP version that supports this function.
Function | Description | PHP |
---|---|---|
basename() | Returns the file name part of the path. | 3 |
chgrp() | Changes the file group. | 3 |
chmod() | Changes the file mode. | 3 |
chown() | Changes the file owner. | 3 |
clearstatcache() | Clears the file status cache. | 3 |
copy() | Copy a file. | 3 |
delete() | See also unlink() or unset(). | |
dirname() | Returns the directory name part of the path. | 3 |
disk_free_space() | Returns the available space of a directory. | 4 |
disk_total_space() | Returns the total disk space of a directory. | 4 |
diskfreespace() | alias of disk_free_space() | 3 |
fclose() | Closes an open file. | 3 |
feof() | Tests if the file pointer is at the end of the file. | 3 |
fflush() | Outputs buffered content to an open file. | 4 |
fgetc() | Returns a character from an open file. | 3 |
fgetcsv() | Parses a line from an open file, validating CSV fields. | 3 |
fgets() | Returns a line from an open file. | 3 |
fgetss() | Reads a line from an open file and filters out HTML and PHP tags. | 3 |
file() | Reads a file into an array. | 3 |
file_exists() | Checks if a file or directory exists. | 3 |
file_get_contents() | Reads a file into a string. | 4 |
file_put_contents() | Writes a string to a file. | 5 |
fileatime() | Returns the last accessed time of the file. | 3 |
filectime() | Returns the last modified time of the file. | 3 |
filegroup() | Return the group ID of the file. | 3 |
fileinode() | Return the inode number of the file. | 3 |
filemtime() | Return the last modified time of the file. | 3 |
fileowner() | File user ID (owner). | 3 |
fileperms() | Return the file permissions. | 3 |
filesize() | Return the file size. | 3 |
filetype() | Return the file type. | 3 |
flock() | Lock or release a file. | 3 |
fnmatch() | Match filenames or strings based on the specified pattern. | 4 |
fopen() | Open a file or URL. | 3 |
fpassthru() | Read data from an open file until EOF, and write the results to the output buffer. | 3 |
fputcsv() | Format a line as CSV and write it to an open file. | 5 |
fputs() | Alias of fwrite(). | 3 |
fread() | Read an open file. | 3 |
fscanf() | Parse input based on the specified format. | 4 |
fseek() | Locate in the open file. | 3 |
fstat() | Return information about an open file. | 4 |
ftell() | Return the read/write position of the file pointer. | 3 |
ftruncate() | Truncate a file to the specified length. | 4 |
fwrite() | Write to a file. | 3 |
glob() | Return an array containing filenames/directories that match the specified pattern. | 4 |
is_dir() | Determine if the specified filename is a directory. | 3 |
is_executable() | Determine if a file is executable. | 3 |
is_file() | Determine if the specified file is a regular file. | 3 |
is_link() | Determine if the specified file is a link. | 3 |
is_readable() | Determine if a file is readable. | 3 |
is_uploaded_file() | Determine if a file is uploaded via HTTP POST. | 3 |
is_writable() | Determine if a file is writable. | 4 |
is_writeable() | Alias of is_writable(). | 3 |
link() | Create a hard link. | 3 |
linkinfo() | Return information about a hard link. | 3 |
lstat() | Return information about the file or symbolic link. | 3 |
mkdir() | Create a directory. | 3 |
move_uploaded_file() | Move the uploaded file to a new location. | 4 |
parse_ini_file() | Parse a configuration file. | 4 |
pathinfo() | Return information about the file path. | 4 |
pclose() | Close the process opened by popen(). | 3 |
popen() | popen() | 3 |
Open a process. | readfile() | 3 |
Read a file and output to the output buffer. | Return the target of the symbolic link. | 3 |
realpath() | Return the absolute path name. | 4 |
rename() | Rename a file or directory. | 3 |
rewind() | Rewind the file pointer position. | 3 |
rmdir() | Delete an empty directory. | 3 |
set_file_buffer() | Set the buffer size of an open file. | 3 |
stat() | Return information about the file. | 3 |
symlink() | Create a symbolic link. | 3 |
tempnam() | Create a unique temporary file. | 3 |
tmpfile() | Create a temporary file. | 3 |
touch() | Set the access and modification time of the file. | 3 |
umask() | Change the file permissions. | 3 |
unlink() | Delete a file. | 3 |
PHP Filesystem Constants
PHP:Indicates the earliest PHP version that supports the constant.
Constants | Description | PHP |
---|---|---|
GLOB_BRACE | ||
GLOB_ONLYDIR | ||
GLOB_MARK | ||
GLOB_NOSORT | ||
GLOB_NOCHECK | ||
GLOB_NOESCAPE | ||
PATHINFO_DIRNAME | ||
PATHINFO_BASENAME | ||
PATHINFO_EXTENSION | ||
FILE_USE_INCLUDE_PATH | ||
FILE_APPEND | ||
FILE_IGNORE_NEW_LINES | ||
FILE_SKIP_EMPTY_LINES |
- Previous Page PHP Error
- Next Page PHP Filter