PHP Tutorials - Herong's Tutorial Examples
∟Functions to Manage Directories, Files and Images
∟file_exists() and File Testing Functions
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.
See the next section for example PHP scripts.
Table of Contents
About This Book
Introduction and Installation of PHP
PHP Script File Syntax
PHP Data Types and Data Literals
Variables, References, and Constants
Expressions, Operations and Type Conversions
Conditional Statements - "if" and "switch"
Loop Statements - "while", "for", and "do ... while"
Function Declaration, Arguments, and Return Values
Arrays - Ordered Maps
Interface with Operating System
Introduction of Class and Object
Integrating PHP with Apache Web Server
Retrieving Information from HTTP Requests
Creating and Managing Sessions in PHP Scripts
Sending and Receiving Cookies in PHP Scripts
Controlling HTTP Response Header Lines in PHP Scripts
Managing File Upload
MySQL Server Connection and Access Functions
►Functions to Manage Directories, Files and Images
opendir() and Directory Management Functions
►file_exists() and File Testing Functions
FileExistsTest.php - File Testing Examples
fopen() and File Input/Output Functions
File_Input_Output_Test.php - File Input/Output Examples
readfile() and Special File Handling Functions
ShowPhoto.php - Simple Slid Show Script
SOAP Extension Function and Calling Web Services
SOAP Server Functions and Examples
Localization Overview of Web Applications
Using Non-ASCII Characters in HTML Documents
Using Non-ASCII Characters as PHP Script String Literals
Receiving Non-ASCII Characters from Input Forms
"mbstring" Extension and Non-ASCII Encoding Management
Managing Non-ASCII Character Strings with MySQL Servers
Parsing and Managing HTML Documents
Configuring and Sending Out Emails
Image and Picture Processing
Managing ZIP Archive Files
Managing PHP Engine and Modules on macOS
Managing PHP Engine and Modules on CentOS
Archived Tutorials
References
Full Version in PDF/EPUB