English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP Filesystem Filesystem Functions

Filesystem functions are used to access and operate the file system, PHP provides all the functions you may need to operate files.

Installation

Filesystem functions are part of the PHP core. 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:

NamedefaultDescriptioncan be changed
allow_url_fopen""1""allows fopen()-The type function uses URL. (PHP 4.0.4 Available from versionPHP_INI_SYSTEM
user_agentNULLDefine the user agent sent by PHP. (PHP 4.3 Available from versionPHP_INI_ALL
default_socket_timeout""6"0"Set the default timeout time (in seconds) for socket streams. (PHP 4.3 Available from versionPHP_INI_ALL
from""Define the password for anonymous FTP (your email address).PHP_INI_ALL
auto_detect_line_endings"0"When set to "1When " is specified, PHP will check if the line terminator in the data obtained through fgets() and file() is in compliance with Unix, MS-Dos or Mac habits. (PHP 4.3 Available from versionPHP_INI_ALL

Unix / Windows compatibility

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

PHP Filesystem Functions

FunctionDescription
basename()Return the file name part of a path.
chgrp()Change the file group.
chmod()Change the file mode.
chown()Change the file owner.
clearstatcache()Clear the file status cache.
copy()Copy a file.
delete()See unlink() or unset()
dirname()Return the directory name part of a path.
disk_free_space()Return the available space of a directory.
disk_total_space()Return the total disk space of a directory.
diskfreespace()Alias of disk_free_space().
fclose()Close an open file.
feof()Test if the file pointer is at the end of the file.
fflush()Flush the output buffer of an open file.
fgetc()Return a character from an open file.
fgetcsv()Parse a line from an open file, validate CSV field.
fgets()Return a line from an open file.
fgetss()Return a line from an open file, filtering out HTML and PHP tags.
file()Read a file into an array.
file_exists()Check if a file or directory exists.
file_get_contents()Read a file into a string.
file_put_contents()Write a string to a file.
fileatime()Return the last access time of the file.
filectime()Return the last modified time of the file.
filegroup()Return the group ID of the file.
fileinode()Return the inode number of the file.
filemtime()Return the last modified time of the file content.
fileowner()Return the user ID (owner) of the file.
fileperms()Return the file permissions.
filesize()Return the file size.
filetype()Return the file type.
flock()Lock or unlock a file.
fnmatch()Match filenames or strings according to the specified pattern.
fopen()Open a file or URL.
fpassthru()Read data from an open file until the end of file (EOF), and write the results to the output buffer.
fputcsv()Format a line as CSV and write it to an open file.
fputs()Alias for fwrite().
fread()Read from an open file.
fscanf()Parse input according to the specified format.
fseek()Locate in an open file.
fstat()Return information about an open file.
ftell()Return the current position in an open file.
ftruncate()Truncate an open file to the specified length.
fwrite()Write to an open file.
glob()Return a list of filenames that match the specified pattern./Array of directories.
is_dir()Determine if a file is a directory.
is_executable()Determine if a file is executable.
is_file()Determine if a file is a regular file.
is_link()Determine if a file is a link.
is_readable()Determine if a file is readable.
is_uploaded_file()Determine if a file was uploaded via HTTP POST.
is_writable()Determine if a file is writable.
is_writeable()Alias for is_writable().
lchgrp()Change the group ownership of a symbolic link.
lchown()Change the user ownership of a symbolic link.
link()Create a hard link.
linkinfo()Return information about a hard link.
lstat()Return information about a file or symbolic link.
mkdir()Create a directory.
move_uploaded_file()Move the uploaded file to a new location.
parse_ini_file()Parse a configuration file.
parse_ini_string()Parse a configuration string.
pathinfo()Return information about the file path.
pclose()Close the process opened by popen().
popen()Open a process.
readfile()Read a file and write it to the output buffer.
readlink()Return the target of the symbolic link.
realpath()Return the absolute path name.
realpath_cache_get()Return a cache entry.
realpath_cache_size()Return the cache size.
rename()Rename a file or directory.
rewind()Rewind the file pointer position.
rmdir()Delete an empty directory.
set_file_buffer()Set the buffer size of an open file.
stat()Return information about the file.
symlink()Create a symbolic link.
tempnam()Create a unique temporary file.
tmpfile()Create a unique temporary file.
touch()Set the access and modification time of the file.
umask()Change the file permissions.
unlink()Delete a file.

PHP error and logging constants

Version-Represents the earliest version of PHP that supports the constant. You can use any constant when configuring the php.ini file.

NumberConstants and descriptionsVersion
1

GLOB_BRACE


2

GLOB_ONLYDIR


3

GLOB_MARK


4

GLOB_NOSORT


5

GLOB_NOCHECK


6

GLOB_NOESCAPE


7

PATHINFO_DIRNAME


8

PATHINFO_BASENAME


9

PATHINFO_EXTENSION


10

PATHINFO_FILENAME

5.2.0
11

FILE_USE_INCLUDE_PATH

Search for the filename in include_path

5.0.0
12

FILE_APPEND

Append content to an existing file.


13

FILE_IGNORE_NEW_LINES

Remove EOL characters

5.0.0
14

FILE_SKIP_EMPTY_LINES

Skip empty lines

5.0.0
15

FILE_BINARY

Binary mode

6.0.0
16

FILE_TEXT

Text mode

6.0.0