UPLOADING FILES Understanding the $_FILES (Web site builder) array What confuses
UPLOADING FILES Understanding the $_FILES array What confuses many people is that their file seems to vanish after it has been uploaded. This is because you can t refer to an uploaded file in the $_POST array in the same way as with text input. PHP transmits the details of uploaded files in a separate superglobal array called, not unreasonably, $_FILES. Moreover, files are uploaded to a temporary folder and are deleted unless you explicitly move them to the desired location. Although this sounds like a nuisance, it s done for a very good reason: you can subject the file to security checks before accepting the upload. The best way to understand how the $_FILES array works is to see it in action. If you have installed a local test environment, you can test everything on your computer. It works in exactly the same way as uploading a file to a remote server. Inspecting the $_FILES array 1. Create a new folder called uploads in the phpsolutions site root. Create a new PHP file called upload.php in the uploads folder, and insert the code from the previous section. Alternatively, copy upload01.php from the download files for this chapter, and rename the file upload.php. 2. Insert the following code right after the closing
tag (it s also in upload02.php):