PHP Function Reference

PHP - Filesystem

The PHP has a number of methods and functions to access and manipulate the filesystem.


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

PHP Filesystem Functions

basename() Return filename from the specified path.
chgrp() Changes file group.
clearstatcache() Clears file status cache.
chown() Changes file owner.
copy() Copies file.
delete() See unlink() function or unset() function.
disk_free_space() Returns available space on filesystem or disk partition.
disk_total_space() Returns the total size of a filesystem or disk partition.
diskfreespace() Returns available space on filesystem or disk partition. Alias of disk_free_space() function.
fclose() Closes an open file pointer.
feof() Tests for end-of-file on a file pointer.
fflush() Flushes the output to a file.
fgetc() Gets character from file pointer.
fgets() Gets line from file pointer.
fgetss() Gets line from file pointer and strip HTML tags.
fileatime() Gets last access time of file.
filectime() Gets inode change time of file.
file_exists() Checks whether a file or directory exists.
filegroup() Gets file group.
fileinode() Gets file inode.
filemtime() Gets file modification time.
fileowner() Gets file owner.
fileperms() Gets file permissions.
filetype() Gets file type.
flock() Portable advisory file locking.
fseek() Seeks on a file pointer.
fopen() Opens file or URL.
fputs() Binary-safe file write. Alias of fwrite() function.
filesize() Gets file size.
ftell() Returns the current position of the file read/write pointer.
ftruncate() Truncates a file to a given length.
fwrite() Binary-safe file write.
is_dir() Tells whether the filename is a directory.
is_executable() Tells whether the filename is executable.
is_file() Tells whether the filename is a regular file.
is_link() Checks whether the filename is a symbolic link.
is_readable() Tells whether a file exists and is readable.
is_writable() Tells whether the filename is writable.
is_writeable() Tells whether the filename is writable. Alias of is_writable() function.
lchgrp() Changes group ownership of symlink.
lchown() Changes user ownership of symlink.
link() Create a hard link
linkinfo() Gets information about a link.
lstat() Gives information about a file or symbolic link.
mkdir() Makes directory.
popen() Opens process file pointer.
readlink() Returns the target of a symbolic link.
stat() Gives information about a file.
readfile() Outputs a file.
rename() Renames a file or directory.
rewind() Rewind the position of a file pointer.
rmdir() Removes directory
set_file_buffer() Sets write file buffering on the given stream. Alias of stream_set_write_buffer() function.
symlink() Creates a symbolic link.
tempnam() Create file with unique file name.
tmpfile() Creates a temporary file.
touch() Sets access and modification time of file.
unlink() Deletes a file.

PHP Filesystem Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

FILE_USE_INCLUDE_PATHIntegerSearch for filename in include_path.
FILE_APPENDIntegerAppend content to existing file.
FILE_IGNORE_NEW_LINESIntegerStrip EOL characters.
FILE_SKIP_EMPTY_LINESIntegerSkip empty lines.
FILE_BINARYIntegerBinary mode. This constant has no effect, and is only available for forward compatibility.
FILE_TEXTIntegerText mode. This constant has no effect, and is only available for forward compatibility.
INI_SCANNER_NORMALIntegerNormal INI scanner mode.
INI_SCANNER_RAWIntegerRaw INI scanner mode.
INI_SCANNER_TYPEDIntegerTyped INI scanner mode.
FNM_NOESCAPEIntegerDisable backslash escaping.
FNM_PATHNAMEIntegerSlash in string only matches slash in the given pattern.
FNM_PERIODIntegerLeading period in string must be exactly matched by period in the given pattern.
FNM_CASEFOLDIntegerCaseless match. Part of the GNU extension.