This section describes some built-in file testing functions. file_exists() allows you test if a directory or file exists or not. is_file() returns true if the given path is a file, not a directory.
PHP offers a lots of nice built-in functions to test and manage files:
disk_total_space($path) - The "disk total space" function returns the total disk space of the specified path in number of bytes.
For example, disk_total_space("/herong") returns the total disk space where /herong is located.
disk_free_space($path) - The "disk free space" function returns the disk free space of the specified path in number of bytes.
For example, disk_free_space("/herong") returns the disk free space where /herong is located.
pathinfo($path) - This "path information" function returns information of the specified path in an array with
element keys of dirname, basename, extension, and filename.
realpath($path) - This "real path" function returns the absolute path name of $path.
dirname - This "directory name" function returns the directory part of the specified path name.
For example, dirname("/herong/html/index.php") returns "/herong/html".
basename($path, $suffix) - This "base name" function returns the file name part of the specified
path name with the specified suffix removed. For example, basename("/herong/html/index.php", ".php")
returns "index".
file_exists($file) - This "file exists" function returns TRUE, if the specified file exists.
fileatime($file) - This "file access time" function returns the time of when the specified file was last accessed.
filemtime($file) - This "file modified time" function returns the time of when the specified file was last modified.
fileperms($file) - This "file permissions" function returns permission settings of the specified file.
filesize($file) - This "file size" function returns the size of the specified file in number of bytes.
filetype($file) - This "file type" function returns the type of the specified file.
stat($path) - This 'statistics" functions returns file information of the specified path in an array with
element keys of dev, ino, mode, nlink, uid, gid, rdev, size, atime, mtime, ctime, blksize, and blocks.
is_dir($path) - This "is directory" function returns TRUE, if the specified path is a directory.
is_file($path) - This "is file" function returns TRUE, if the specified path is a file.
is_executable($path) - This "is executable" function returns TRUE, if the specified path is an executable program.
is_readable($path) - This "is readable" function returns TRUE, if the specified path is a readable file.
is_writable($path) - This "is writable" function returns TRUE, if the specified path is a writable file.
copy($source, $dest ) - This "copy" function copies a file specified as the source to a new file specified as
the destination.
rename($old_name, $new_name) - This "rename" function renames a file or a directory.
unlink($path) - This "un link" function removes the link to an actual file of the specified path.
If this is the last link, the actual file will be removed.
unlink() removes the actual file on Windows systems, since links are not supported on Windows systems.