YouTip LogoYouTip

Php Ref Filesystem

```html PHP 5 Filesystem Functions | Tutorial for Beginners

Introduction to PHP Filesystem

The Filesystem functions allow you to access and manipulate the filesystem.

Installation

The Filesystem functions are part of the PHP core. These functions can be used without installation.

Runtime Configuration

The behavior of the Filesystem functions is affected by settings in php.ini.

Filesystem configuration options:

Name Default Description Changeable
allow_url_fopen "1" Allows fopen()-type functions to use URLs. (Available since PHP 4.0.4) PHP_INI_SYSTEM
user_agent NULL Defines the User-Agent sent by PHP. (Available since PHP 4.3) PHP_INI_ALL
default_socket_timeout "60" Sets the default timeout for socket-based stream operations, in seconds. (Available since PHP 4.3) PHP_INI_ALL
from "" Defines the password for anonymous FTP (your e-mail address). PHP_INI_ALL
auto_detect_line_endings "0" When set to "1", PHP will check the line endings of data obtained through fgets() and file() to see if they follow the Unix, MS-Dos, or Mac conventions. (Available since PHP 4.3) PHP_INI_ALL

Unix / Windows Compatibility

When specifying paths on a Unix platform, the forward slash (/) is used as a directory separator. On Windows platforms, both the forward slash (/) and the backslash () are usable.

PHP 5 Filesystem Functions

Function Description
basename() Returns the filename portion of a path.
chgrp() Changes file group.
chmod() Changes file mode.
chown() Changes file owner.
clearstatcache() Clears file status cache.
copy() Copies a file.
delete() See unlink() or unset().
dirname() Returns the directory name portion of a path.
disk_free_space() Returns the available space of a directory.
disk_total_space() Returns the total capacity of a filesystem or disk partition.
diskfreespace() Alias of disk_free_space().
fclose() Closes an open file pointer.
feof() Tests for end-of-file on a file pointer.
fflush() Flushes the output to an open file.
fgetc() Gets a character from an open file.
fgetcsv() Parses a line from an open file for CSV fields.
fgets() Gets a line from an open file.
fgetss() Gets a line from an open file and strip HTML and PHP tags.
file() Reads entire file into an array.
file_exists() Checks whether a file or directory exists.
file_get_contents() Reads entire file into a string.
file_put_contents() Write a string to a file.
fileatime() Returns the last access time of the file.
filectime() Returns the last change time of the file.
filegroup() Returns the group id of the file.
fileinode() Returns the inode number of the file.
filemtime() Returns the time the file was last modified.
fileowner() Returns the user id (owner) of the file.
fileperms() Returns the permissions of the file.
filesize() Returns the size of the file.
filetype() Returns the type of the file.
flock() Locks or releases a file.
fnmatch() Match filename against a pattern.
fopen() Opens a file or URL.
fpassthru() Output all remaining data on a file pointer.
fputcsv() Format a line as CSV and write to a file pointer.
fputs() Alias of fwrite().
fread() Binary-safe file read.
fscanf() Parses input from a file according to a format.
fseek() Seeks on a file pointer.
fstat() Gathers the statistics of an open file.
ftell() Returns the current position of the file read/write pointer.
ftruncate() Truncates a file to a given length.
fwrite() Binary-safe file write.
glob() Finds pathnames matching a pattern.
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() Tells whether the filename is a symbolic link.
is_readable() Tells whether a file exists and is readable.
is_uploaded_file() Tells whether the file was uploaded via HTTP POST.
is_writable() Tells whether the filename is writable.
is_writeable() Alias of is_writable().
lchgrp() Changes group ownership of symlink.
lchown() Changes user ownership of symlink.
link() Create a hard link.
linkinfo() Returns information about a hard link.
lstat()
```
← Php Ref FilterPhp Ref Error β†’