Wrapper Overview
As long as thereâs a wrapper that supports it, you can use streams to read from and write to any location or protocol using the same set of file manipulation functions from the previous section.
For example, here are a few streams that access nonlocal files:
http://www.example.com/index.html
https://secure.example.com/secret.html
ftp://user:password@ftp.example.com/www/www.example.com/index.html
The first stream makes an HTTP request to
www.example.com and retrieves the file from the
Internet. The second makes a secure HTTP connection using SSL and
accesses secret.html
from
secure.example.com. The final wrapper transfers
a file using FTP, passing along a username and
password
in the process.
However, while streams do abstract away most implementation specifics, they canât alter the inherent nature of the protocol itself. For instance, although itâs quite easy to read files using HTTP, most web servers are not set up to allow you to save files using HTTP. Likewise, when you use FTP, you need to provide a username and password or the FTP server wonât be able to authenticate you as a legitimate user.
Bundled Wrappers
Before getting into the specifics of each individual wrapper, hereâs a brief overview of all the wrappers bundled with PHP 5, as well as the additional wrappers you can enable with certain extensions.
PHP 5 automatically provides you with four wrappers:
-
file
Talks to the local filesystem
-
http
Requests a file from a web server
-
ftp
Reads and ...
Get Upgrading to PHP 5 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.