Specifications

Creating, Deleting, and Moving Files
You can use the file system functions to create, move, and delete files.
First, and most simply, you can create a file, or change the time it was last modified, using the
touch() function. This works similarly to the UNIX command touch. The function has the fol-
lowing prototype:
int touch (string file, [int time])
If the file already exists, its modification time will be changed either to the current time, or the
time given in the second parameter if it is specified. If you want to specify this, it should be
given in time stamp format. If the file doesnt exist, it will be created.
You can also delete files using the
unlink() function. (Note that this function is not called
deletethere is no delete.) You use it like this:
unlink($filename);
This is one of the functions that doesnt work with the Win32 build. However, you can delete a
file in Windows with
system(“del filename.ext”);
You can copy and move files with the copy() and rename() functions, as follows:
copy($source_path, $destination_path);
rename($oldfile, $newfile);
You might have noticed that we used copy() in Listing 16.2.
The rename() function does double duty as a function to move files from place to place
because PHP doesnt have a move function. Whether you can move files from file system to
file system, and whether files are overwritten when rename() is used is operating system
dependent, so check the effects on your server. Also, be careful about the path you use to the
filename. If relative, this will be relative to the location of the script, not the original file.
Using Program Execution Functions
Well move away from the file system functions now, and look at the functions that are avail-
able for running commands on the server.
This is useful when you want to provide a Web-based front end to an existing command line-
based system. For example, we have used these commands to set up a front end for the mailing
list manager ezmlm. We will use these again when we come to the case studies later in this
book.
Interacting with the File System and the Server
C
HAPTER 16
16
INTERACTING WITH
THE
F
ILE SYSTEM
AND THE
SERVER
365
21 7842 CH16 3/6/01 3:40 PM Page 365