List of All File functions in php

Introduction

If you were having trouble in remembering all file related functions of PHP, then don't worry, I'm publishing here a full list of all of them, so that you can easily use any of them. File system related functions were divided into 9 extensions of php whose names are shown below.

List of File system related extensions

Click on links to directly Jump on page section.

  1. Direct IO,
  2. Directories,
  3. Fileinfo,
  4. Filesystem,
  5. Inotify,
  6. Mimetype (No functions found),
  7. Proctile,
  8. xattr,
  9. And xdiff.

Below is the division of functions in each of those file extensions of php.

Filesystem functions in php

Function Name
Description
Syntax
Other information
basename
Given a string containing the path to a file or directory, this function will return the trailing name component.
basename ( string $path [, string $suffix ] )
 
chgrp
Changes file group
chgrp ( string $filename , mixed $group )
group - A group name or number.
chmod
Attempts to change the mode of the specified file to that given in $mode.
chmod ( string $filename , int $mode )
Returns TRUE on success or FALSE on failure.
chown
Attempts to change the owner of the file $filename to $user user. Only the superuser may change the owner of a file.
chown ( string $filename , mixed $user )
filename - path to the file, user - A user name or number.
clearstatcache
Clears file status cache
clearstatcache ([ bool $clear_realpath_cache = false [, string $filename ]] )
clear_realpath_cache - Whether to clear the realpath cache or not.
copy
Makes a copy of the file $source to $dest.
copy ( string $source , string $dest [, resource $context ] )
Returns TRUE on success or FALSE on failure.
delete
This is a dummy manual entry to satisfy those people who are looking for unlink() or unset() in the wrong place.
delete ( void )
 
dirname
Given a string containing the path of a file or directory, this function will return the parent directory's path.
dirname ( string $path )
 
disk_free_space
Given a string containing a directory, this function will return the number of bytes available on the corresponding filesystem or disk partition.
disk_free_space ( string $directory )
 
disk_total_space
Given a string containing a directory, this function will return the total number of bytes on the corresponding filesystem or disk partition.
disk_total_space ( string $directory )
Returns the total number of bytes as a float or FALSE on failure.
diskfreespace
This function is an alias of: disk_free_space().
 
 
fclose
The file pointed to by handle is closed.
fclose ( resource $handle )
handle - The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen().
feof
Tests for end-of-file on a file pointer.
feof ( resource $handle )
The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()).
fflush
This function forces a write of all buffered output to the resource pointed to by the file handle.
fflush ( resource $handle )
Returns TRUE on success or FALSE on failure.
fgetc
Gets a character from the given file pointer.
fgetc ( resource $handle )
Returns a string containing a single character read from the file pointed to by handle. Returns FALSE on EOF.
fgetcsv
Similar to fgets() except that fgetcsv() parses the line it reads for fields in CSV format and returns an array containing the fields read.
fgetcsv ( resource $handle [, int $length = 0 [, string $delimiter = ',' [, string $enclosure = '"' [, string $escape = '\\' ]]]] )
handle - A valid file pointer to a file successfully opened by fopen(), popen(), or fsockopen().
fgets
Gets a line from file pointer.
fgets ( resource $handle [, int $length ] )
length - If no length is specified, it will keep reading from the stream until it reaches the end of the line.
fgetss
Identical to fgets(), except that fgetss() attempts to strip any NUL bytes, HTML and PHP tags from the text it reads.
fgetss ( resource $handle [, int $length [, string $allowable_tags ]] )
allowable_tags - You can use the optional third parameter to specify tags which should not be stripped.
file_exists
Checks whether a file or directory exists.
file_exists ( string $filename )
 
file_get_contents
Reads entire file into a string
file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )
 
file_put_contents
This function is identical to calling fopen(), fwrite() and fclose() successively to write data to a file.
file_put_contents ( string $filename , mixed $data [, int $flags = 0 [, resource $context ]] )
 
file
Reads an entire file into an array.
file ( string $filename [, int $flags = 0 [, resource $context ]] )
 
fileatime
Gets the last access time of the given file.
fileatime ( string $filename )
 
filectime
Gets the inode change time of a file.
filectime ( string $filename )
 
filegroup
Gets the file group. The group ID is returned in numerical format, use posix_getgrgid() to resolve it to a group name.
filegroup ( string $filename )
 
fileinode
Gets the file inode.
fileinode ( string $filename )
Returns the inode number of the file, or FALSE on failure.
filemtime
This function returns the time when the data blocks of a file were being written to, that is, the time when the content of the file was changed.
filemtime ( string $filename )
Returns the time the file was last modified, or FALSE on failure. The time is returned as a Unix timestamp, which is suitable for the date() function.
fileowner
Gets the file owner.
fileowner ( string $filename )
Returns the user ID of the owner of the file, or FALSE on failure. The user ID is returned in numerical format, use posix_getpwuid() to resolve it to a username.
fileperms
Gets permissions for the given file.
fileperms ( string $filename )
Returns the permissions on the file, or FALSE on failure.
filesize
Gets the size for the given file.
filesize ( string $filename )
 
filetype
Returns the type of the given file.
filetype ( string $filename )
Returns the type of the file. Possible values are fifo, char, dir, block, link, file, socket and unknown.
flock
Portable advisory file locking
flock ( resource $handle , int $operation [, int &$wouldblock ] )
 
fnmatch
Match filename against a pattern
fnmatch ( string $pattern , string $string [, int $flags = 0 ] )
 
fopen
Opens file or URL
fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )
 
fpassthru
Output all remaining data on a file pointer
fpassthru ( resource $handle )
 
fputcsv
Format line as CSV and write to file pointer
fputcsv ( resource $handle , array $fields [, string $delimiter = ',' [, string $enclosure = '"' ]] )
 
fputs
This function is an alias of: fwrite().
 
 
fread
Binary-safe file read
fread ( resource $handle , int $length )
 
fscanf
Parses input from a file according to a format
fscanf ( resource $handle , string $format [, mixed &$... ] )
 
fseek
Seeks on a file pointer
fseek ( resource $handle , int $offset [, int $whence = SEEK_SET ] )
 
fstat
Gets information about a file using an open file pointer
fstat ( resource $handle )
handle - A file system pointer resource that is typically created using fopen().
ftell
Returns the position of the file pointer referenced by handle.
ftell ( resource $handle )
 
ftruncate
Truncates a file to a given length
ftruncate ( resource $handle , int $size )
 
fwrite
Binary-safe file write
fwrite ( resource $handle , string $string [, int $length ] )
 
glob
Find pathnames matching a pattern
glob ( string $pattern [, int $flags = 0 ] )
 
is_dir
Tells whether the given filename is a directory.
is_dir ( string $filename )
 
is_executable
Tells whether the filename is executable.
is_executable ( string $filename )
 
is_file
Tells whether the given file is a regular file.
is_file ( string $filename )
 
is_link
Tells whether the given file is a symbolic link.
is_link ( string $filename )
 
is_readable
Tells whether a file exists and is readable.
is_readable ( string $filename )
 
is_uploaded_file
Tells whether the file was uploaded via HTTP POST
is_uploaded_file ( string $filename )
 
is_writable
Tells whether the filename is writable
is_writable ( string $filename )
 
is_writeable
This function is an alias of: is_writable().
 
 
lchgrp
Changes group ownership of symlink
lchgrp ( string $filename , mixed $group )
 
lchown
Changes user ownership of symlink
lchown ( string $filename , mixed $user )
 
link
link() creates a hard link.
link ( string $target , string $link )
 
linkinfo
Gets information about a link
linkinfo ( string $path )
 
lstat
Gives information about a file or symbolic link
lstat ( string $filename )
 
mkdir
Attempts to create the directory specified by pathname.
mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )
 
move_uploaded_file
Moves an uploaded file to a new location
move_uploaded_file ( string $filename , string $destination )
 
parse_ini_file
Parse a configuration file
parse_ini_file ( string $filename [, bool $process_sections = false [, int $scanner_mode = INI_SCANNER_NORMAL ]] )
 
parse_ini_string
Parse a configuration string
parse_ini_string ( string $ini [, bool $process_sections = false [, int $scanner_mode = INI_SCANNER_NORMAL ]] )
 
pathinfo
pathinfo() returns an associative array containing information about path.
pathinfo ( string $path [, int $options = PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME ] )
 
pclose
Closes a file pointer to a pipe opened by popen().
pclose ( resource $handle )
Returns the termination status of the process that was run. In case of an error then -1 is returned.
popen
Opens process file pointer
popen ( string $command , string $mode )
 
readfile
Outputs a file
readfile ( string $filename [, bool $use_include_path = false [, resource $context ]] )
 
readlink
Returns the target of a symbolic link
readlink ( string $path )
 
realpath_cache_get
Get the contents of the realpath cache.
realpath_cache_get ( void )
Returns an array of realpath cache entries. The keys are original path entries, and the values are arrays of data items, containing the resolved path, expiration date, and other options kept in the cache.
realpath_cache_size
Get the amount of memory used by the realpath cache.
realpath_cache_size ( void )
 
realpath
Returns canonicalized absolute pathname
realpath ( string $path )
 
rename
Attempts to rename oldname to newname.
rename ( string $oldname , string $newname [, resource $context ] )
 
rewind
Sets the file position indicator for handle to the beginning of the file stream.
rewind ( resource $handle )
 
rmdir
Removes directory
rmdir ( string $dirname [, resource $context ] )
 
set_file_buffer
This function is an alias of: stream_set_write_buffer().
 
 
stat
Gives information about a file
stat ( string $filename )
 
symlink
Creates a symbolic link
symlink ( string $target , string $link )
 
tempnam
Create file with unique file name
tempnam ( string $dir , string $prefix )
Returns the new temporary filename, or FALSE on failure.
tmpfile
Creates a temporary fileCreates a temporary file with a unique name in read-write (w+) mode and returns a file handle .
tmpfile ( void )
 
touch
Sets access and modification time of file
touch ( string $filename [, int $time = time() [, int $atime ]] )
 
umask
Changes the current umask
umask ([ int $mask ] )
 
unlink
Deletes a file
unlink ( string $filename [, resource $context ] )
Returns TRUE on success or FALSE on failure.

Direct IO functions in php

Function Name
Description
Syntax
Other Information
dio_close
Closes the file description given by fd
dio_close(resource $fd)
fd - The file descriptor returned by dio_open()
dio_fcntl
The dio_fcntl() function performs the operation specified by cmd on the file descriptor fd. Some commands require additional arguments args to be supplied.
dio_fcntl ( resource $fd , int $cmd [, mixed $args ] )
cmd - can be F_SETLK, F_SETLKW, F_GETLK, F_DUPFD, F_SETFL
dio_open
dio_open() opens a file and returns a new file descriptor for it.
dio_open ( string $filename , int $flags [, int $mode = 0 ] )
filename - Path of the file to open.
dio_read
The function dio_read() reads and returns len bytes from file with descriptor fd.
string dio_read ( resource $fd [, int $len = 1024 ] )
len - Number of Bytes to read.
dio_seek
The function dio_seek() is used to change the file position of the given file descriptor.
dio_seek ( resource $fd , int $pos [, int $whence = SEEK_SET ] )
pos - The new position, Whence -Specifies how the position pos should be interpreted.
dio_stat
dio_stat() returns information about the given file descriptor.
dio_stat ( resource $fd )
fd - The file descriptor returned by dio_open().
dio_tcsetattr
dio_tcsetattr() sets the terminal attributes and baud rate of the open fd.
dio_tcsetattr ( resource $fd , array $options )
Currently available options are 'baud' , 'bits', 'stop', 'parity'.
dio_truncate
dio_truncate() truncates a file to at most offset bytes in size.
The offset in bytes.
Returns TRUE on success or FALSE on failure.
dio_write
dio_write() writes up to len bytes from data to file fd.
int dio_write ( resource $fd , string $data [, int $len = 0 ] )
data - The written data.

Directory functions in PHP

Function Name
Description
Syntax
Other Information
chdir
Changes PHP's current directory to new directory.
chdir ( string $directory )
directory - The new current directory
chroot
Changes the root directory of the current process to directory, and changes the current working directory to "/".
chroot ( string $directory )
directory - The path to change the root directory to.
dir
Return an instance of the Directory class
-
object-oriented mechanism (search google)
closedir
Closes the directory stream indicated by dir_handle. The stream must have previously been opened by opendir().
closedir ([ resource $dir_handle ] )
dir_handle - The directory handle resource previously opened with opendir(). If the directory handle is not specified, the last link opened by opendir() is assumed.
getcwd
Gets the current working directory.
getcwd ( )
Returns the current working directory on success, or FALSE on failure.
opendir
Opens up a directory handle to be used in subsequent closedir(), readdir(), and rewinddir() calls.
opendir ( string $path [, resource $context ] )
path - The directory path that is to be opened
readdir
Returns the filename of the next file from the directory. The filenames are returned in the order in which they are stored by the filesystem.
readdir ([ resource $dir_handle ] )
Returns the filename on success or FALSE on failure.
rewinddir
Resets the directory stream indicated by dir_handle to the beginning of the directory.
rewinddir ([ resource $dir_handle ] )
 
scandir
Returns an array of files and directories from the directory.
scandir ( string $directory [, int $sorting_order = 0 [, resource $context ]] )
sorting_order - By default, the sorted order is alphabetical in ascending order. If the optional sorting_order is set to non-zero, then the sort order is alphabetical in descending order.

Fileinfo functions in PHP

Function Name
Description
Syntax
Other Information
finfo_buffer
This function is used to get information about binary data in a string.
finfo_buffer ( resource $finfo , string $string = NULL [, int $options = FILEINFO_NONE [, resource $context = NULL ]] )
finfo - Fileinfo resource returned by finfo_open(), $string - Content of a file to be checked,
finfo_close
This function closes the resource opened by finfo_open().
finfo_close ( resource $finfo )
finfo - Fileinfo resource returned by finfo_open().
finfo_file
This function is used to get information about a file.
finfo_file ( resource $finfo , string $file_name = NULL [, int $options = FILEINFO_NONE [, resource $context = NULL ]] )
file_name - Name of a file to be checked.
finfo_open
This function opens a magic database and returns its resource.
finfo_open ([ int $options = FILEINFO_NONE [, string $magic_file = NULL ]] )
Name of a magic database file, usually something like /path/to/magic.mime. If not specified, the MAGIC environment variable is used. If this variable is not set either, /usr/share/misc/magic is used by default. A .mime and/or .mgc suffix is added if needed.
finfo_set_flags
This function sets various Fileinfo options. Options can be set also directly in finfo_open() or other Fileinfo functions.
finfo_set_flags ( resource $finfo , int $options )
Returns TRUE on success or FALSE on failure.
mime_content_type
Returns the MIME content type for a file as determined by using information from the magic.mime file.
mime_content_type ( string $filename )
filename - Path to the tested file.

Inotify functions in PHP

Function Name
Description
Syntax
Other Information
inotify_add_watch
inotify_add_watch() adds a new watch or modify an existing watch for the file or directory specified in pathname.
inotify_add_watch ( resource $inotify_instance , string $pathname , int $mask )
inotify_instance - Resource returned by inotify_init()
inotify_init
Initialize an inotify instance for use with inotify_add_watch()
inotify_init ( void )
 
inotify_queue_len
This function allows to know if inotify_read() will block or not. If a number upper than zero is returned, there are pending events and inotify_read() will not block.
inotify_queue_len ( resource $inotify_instance )
 
inotify_read
Read inotify events from an inotify instance.
inotify_read ( resource $inotify_instance )
 
inotify_rm_watch
Remove an existing watch from an inotify instance
inotify_rm_watch ( resource $inotify_instance , int $watch_descriptor )
watch_descriptor - Watch to remove from the instance

Proctile functions in PHP

Function Name
Description
Syntax
Other Information
setproctitle
Sets the process title of the current process.
setproctitle ( string $title )
title - The title to use as the process title.
setthreadtitle
Sets the thread title.
setthreadtitle ( string $title )
Returns TRUE on success or FALSE on failure.
 
 
 
 

xattr functions of php

Function Name
Description
Syntax
Other Information
xattr_get
This function gets the value of an extended attribute of a file.
xattr_get ( string $filename , string $name [, int $flags = 0 ] )
filename - The file from which we get the attribute, name - The name of the attribute.
xattr_list
This functions gets a list of names of extended attributes of a file.
xattr_list ( string $filename [, int $flags = 0 ] )
filename - The path of the file.
xattr_remove
This function removes an extended attribute of a file.
xattr_remove ( string $filename , string $name [, int $flags = 0 ] )
 
xattr_set
This function sets the value of an extended attribute of a file.
xattr_set ( string $filename , string $name , string $value [, int $flags = 0 ] )
value - The value of the attribute
xattr_supported
This functions checks if the filesystem holding the given file supports extended attributes. Read access to the file is required.
xattr_supported ( string $filename [, int $flags = 0 ] )
filename - The path of the tested file.

xdiff functions in PHP

Function Name
Description
Syntax
Other Information
xdiff_file_bdiff_size
Returns a size of a result file that would be created after applying binary patch from file file to the original file.
xdiff_file_bdiff_size ( string $file )
file - The path to the binary patch created by xdiff_string_bdiff() or xdiff_string_rabdiff() function.
xdiff_file_bdiff
Make binary diff of two files
xdiff_file_bdiff ( string $old_file , string $new_file , string $dest )
dest - Path of the resulting patch file. Resulting file contains differences between "old" and "new" files. It is in binary format and is human-unreadable.
xdiff_file_bpatch
Patch a file with a binary diff
xdiff_file_bpatch ( string $file , string $patch , string $dest )
dest - Path of the resulting file, patch - The binary patch file.
xdiff_file_diff_binary
Alias of xdiff_file_bdiff
xdiff_file_diff_binary ( string $old_file , string $new_file , string $dest )
 
xdiff_file_diff
Make unified diff of two files
xdiff_file_diff ( string $old_file , string $new_file , string $dest [, int $context = 3 [, bool $minimal = false ]] )
 
xdiff_file_merge3
Merge 3 files into one
xdiff_file_merge3 ( string $old_file , string $new_file1 , string $new_file2 , string $dest )
dest - Path of the resulting file, containing merged changed from both new_file1 and new_file2.
xdiff_file_patch_binary
Alias of xdiff_file_bpatch
xdiff_file_patch_binary ( string $file , string $patch , string $dest )
 
xdiff_file_patch
Patch a file with an unified diff
xdiff_file_patch ( string $file , string $patch , string $dest [, int $flags = DIFF_PATCH_NORMAL ] )
 
xdiff_file_rabdiff
Make binary diff of two files using the Rabin's polynomial fingerprinting algorithm
xdiff_file_rabdiff ( string $old_file , string $new_file , string $dest )
 
xdiff_string_bdiff_size
Returns a size of a result file that would be created after applying binary $patch to the original file.
xdiff_string_bdiff_size ( string $patch )
patch - The binary patch created by xdiff_string_bdiff() or xdiff_string_rabdiff() function.
xdiff_string_bdiff
Make binary diff of two strings
xdiff_string_bdiff ( string $old_data , string $new_data )
 
xdiff_string_bpatch
Patch a string with a binary diff
xdiff_string_bpatch ( string $str , string $patch )
 
xdiff_string_diff_binary
Alias of xdiff_string_bdiff
xdiff_string_bdiff ( string $old_data , string $new_data )
 
xdiff_string_diff
Make unified diff of two strings
xdiff_string_diff ( string $old_data , string $new_data [, int $context = 3 [, bool $minimal = false ]] )
 
xdiff_string_merge3
Merge 3 strings into one
xdiff_string_merge3 ( string $old_data , string $new_data1 , string $new_data2 [, string &$error ] )
 
xdiff_string_patch_binary
Alias of xdiff_string_bpatch
xdiff_string_patch_binary ( string $str , string $patch )
 
xdiff_string_patch
Patch a string with an unified diff
xdiff_string_patch ( string $str , string $patch [, int $flags [, string &$error ]] )
 
xdiff_string_rabdiff
Make binary diff of two strings using the Rabin's polynomial fingerprinting algorithm
xdiff_string_bdiff ( string $old_data , string $new_data )
 

So, these are all the filesystem related functions in PHP as of latest version and Source of this information is official PHP website. I hope, you don't find any difficulty in reading this article. If you've been stuck on something, then, you're free to post your queries here below in comments section.

Thanks for reading.

More by this Author


Comments 3 comments

Saras 5 years ago

Very useful and informative details Shri. Thanks for sharing the information.


itech profile image

itech 5 years ago from New Delhi, India Author

Thanks for commenting sir.


paxwill profile image

paxwill 4 years ago from France

Great list! Thanks for making a nice and easy reference.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working