readfile() and Special File Handling Functions
This section describes some special file handling functions. readfile() copies a file to standard output. fgetss() reads a line with tags removed. tmpfile() opens a temporary file. file() reads a file into an array.
PHP also offers a number of other built-in functions to perform some special file input and output tasks:
- file_get_contents($path) - This "file get contents" returns the entire content of the specified file as a string.
- file_put_contents($path, $data) - This "file put contents" writes the specified data to the specified file.
- file($path) - This "file" function returns the entire content of the specified file as an array. Each element
in the array represents one line in the file.
- readfile($path) - This "read file" function reads the entire content of a file and writes to the standard output.
- fpassthru($file) - This "file pass through" function reads remaining data from $file and writes to the standard output.
- fgetss($file) - This "file get string strip" function reads one line from $file and returns it as a string
with HTML and PHP tags stripped off.
- fgetcsv($file) - This "file get CSV" function reads one line from $file and returns it as an array
by parsing the line in CSV format into array elements.
- fputcsv($file,$array) - This "file put CSV" function writes elements from $array to $file in CSV format.
- tmpfile() - This "temporary file" function opens a temporary file in read-write (w+) mode and returns the file resource handle.
This temporary file will be removed with its file resource handle is closed.
- tempnam($path,$prefix) - This "temporary name" function creates a temporary file name in $path with a $prefix.
Table of Contents
About This Book
Introduction and Installation of PHP 7.3
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
Full Version in PDF/EPUB