Specifications

As you can see, the form has a box where the user can enter a filename, or click the Browse
button to browse files available to him locally. You might not have seen a file upload form
before. Well look at how to implement this in a moment.
After a filename has been entered, the user can click Send File, and the file will be uploaded to
the server, where a PHP script is waiting for it.
HTML for File Upload
In order to implement file upload, we need to use some HTML syntax that exists specially for
this purpose. The HTML for this form is shown in Listing 16.1.
LISTING 16.1 upload.htmlHTML Form for File Upload
<html>
<head>
<title>Administration - upload new files</title>
</head>
<body>
<h1>Upload new news files</h1>
<form enctype=”multipart/form-data” action=”upload.php” method=post>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”1000”>
Upload this file: <input name=”userfile” type=”file”>
<input type=”submit” value=”Send File”>
</form>
</body>
</html>
Note that this form uses POST. File uploads will also work with the PUT method supported by
Netscape Composer and Amaya. They will not work with GET.
The extra features in this form are
In the <form> tag, you must set the attribute enctype=”multipart/form-data” to let the
server know that a file is coming along with the regular form information.
You must have a form field that sets the maximum size file that can be uploaded. This is
a hidden field, and is shown here as
<input type=”hidden” name=”MAX_FILE_SIZE” value=”1000”>
The name of this form field must be MAX_FILE_SIZE. The value is the maximum size (in
bytes) of files you will allow people to upload.
You need an input of type file, shown here as
<input name=”userfile” type=”file”>
Interacting with the File System and the Server
C
HAPTER 16
16
INTERACTING WITH
THE
F
ILE SYSTEM
AND THE
SERVER
353
21 7842 CH16 3/6/01 3:40 PM Page 353