Specifications

LISTING 28.14 Continued
</td>
</form>
</tr>
</table>
<?
}
The thing to note here is that the files we want to upload will have their names entered in a
series of inputs, each of type
file, and with names that range from userfile[0] to
userfile[n]. In essence, we are treating these form fields in the same way that we would
treat check boxes, and naming them using an array convention.
If you want to upload multiple files through a PHP script, you need to follow this convention.
In the script that processes this form, we will actually end up with three arrays. Lets look at
that script.
Handling Multiple File Upload
You might remember that we put the file upload code in a separate file. The complete listing of
that file, upload.php, is shown in Listing 28.15.
LISTING 28.15 upload.phpThis Script Uploads All the Files Needed for a Newsletter
<?
// this functionality is in a separate file to allow us to be
// more paranoid with it
// if anything goes wrong, we will exit
$max_size = 50000;
include (‘include_fns.php’);
session_start();
// only admin users can upload files
if(!check_admin_user())
{
echo “You do not seem to be authorized to use this page.”;
exit;
}
// set up the admin toolbar buttons
$buttons = array();
Building Practical PHP and MySQL Projects
P
ART V
698
34 7842 CH28 3/6/01 3:46 PM Page 698