Specifications

Advanced PHP Techniques
P
ART IV
352
In Chapter 2, Storing and Retrieving Data, we saw how to read data from and write data to
files on the Web server. In this chapter, we will cover other PHP functions that enable us to
interact with the file system on the Web server.
We will discuss
Uploading files with PHP
Using directory functions
Interacting with files on the server
Executing programs on the server
Using server environment variables
In order to discuss the uses of these functions, we will look at an example.
Consider a situation in which you would like your client to be able to update some of a Web
sites contentfor instance, the current news about their company. (Or maybe you want a
friendlier interface than FTP for yourself.) One approach to this is to let the client upload the
content files as plain text. These files will then be available on the site, through a template you
have designed with PHP, as we did in Chapter 6, Object Oriented PHP.
Before we dive into the file system functions, lets briefly look at how file upload works.
Introduction to File Upload
One very useful piece of PHP functionality is support for HTTP upload. Instead of files com-
ing from the server to the browser using HTTP, they go in the opposite direction, that is, from
the browser to the server. Usually you implement this with an HTML form interface. The one
well use in our example is shown in Figure 16.1.
FIGURE 16.1
The HTML form we use for file upload has different fields and field types from those of a normal HTML form.
21 7842 CH16 3/6/01 3:40 PM Page 352