Title: Uploading Files ($$$)
Course: PHP/MySQL Course

The $_FILES array

Read page 217 about the $_FILES array.

When a user submits a input field of type 'file' then the file is copied to a temporary location by PHP on the server computer, and the you will need to write code to copy the file from the temporary location to some where within your user area folders that you have permission to write.

This array has two associative keys, the first is the name of the input field on the form. the second is what information you want about the file uploaded. This allows you to have multiple file uploads on the same form, just make each input tag have a different name attribute value.

What does the key tmp_name return when used as the second associative key on the $_FILES array

- The path to the temporary file, so your php code can copy it
- the path of where your user directory is
- the temporary name for the web form
- the tmp name of the submit button

The upload form

Read page 218 about the upload form

NOTE: the form attribute enctype='multipart/form-data' is very important to support uploading files.

Also, the maximum size of the upload is ultimatly set bye both the web server software configuration file and by the php.ini configuration file.

The CBIS3.lbcc.edu server will not allow a file greater than 2 megabytes in length.

What is the value of type for a input field designed to upload files

- upload
- file
- files
- upload_file

PHP code to process upload

Read pages 219 to the end of the chapter about the php code to handle uploading a file.

NOTES:
The foreach($_FILES as $file_name => $file_array) will go thought and for each form input of type file, it will set $file_name to the name attribute of the input field and the $file_array to the one dimensional array listed with the keys: tmp_name, name, type, and size.

If you form only has one upload input tag, then you do not need a loop but can directly access the array as shown in the chart on page 217.

ALSO note that there are a bunch of typographical errors in the code on page 219, there are extra double and single quotes around and inside the associative key names on lines 4, 5 ,6 ,7 ,9 and 10. For example, line 4 should be:
echo "path: " . $file_array['tmp_name'] . "<br />\n";

What is the function to use to tell if a file was uploaded

- is_uploaded_file