Page 296 - Beginning PHP 5.3
P. 296

Part III: Using PHP in Practice
                   Here ’ s a full list of the elements stored in each nested array within the  $_FILES  array:


                      Array Element        Description

                       name             The filename of the uploaded file.
                       type             The MIME type of the uploaded file. For example, a JPEG image would
                                    probably have a MIME type of   image/jpeg , whereas a QuickTime movie file
                                    would have a MIME type of   video/quicktime .
                       size             The size of the uploaded file, in bytes.

                       tmp_name           The full path to the temporary file on the server that contains the uploaded
                                    file. (All uploaded files are stored as temporary files until they are needed.)
                       error            The error or status code associated with the file upload.


                  The  error  element contains an integer value that corresponds to a built - in constant that explains the
                 status of the uploaded file. Possible values include:


                      Constant                  Value        Meaning
                       UPLOAD_ERR_OK               0       The file was uploaded successfully.

                       UPLOAD_ERR_INI_SIZE         1           The file is bigger than the allowed file size specified
                                                        in the   upload_max_filesize  directive in the  php.
                                                        ini  file.
                       UPLOAD_ERR_FORM_SIZE         2           The file is bigger than the allowed file size specified
                                                        in the   MAX_FILE_SIZE  directive in the form.

                       UPLOAD_ERR_NO_FILE           4       No file was uploaded.
                       UPLOAD_ERR_NO_TMP_DIR         6           PHP doesn ’ t have access to a temporary folder on
                                                        the server to store the file.

                       UPLOAD_ERR_CANT_WRITE         7       The file couldn ’ t be written to the server ’ s hard disk
                                                        for some reason.

                       UPLOAD_ERR_EXTENSION         8           The file upload was stopped by one of the currently
                                                        loaded PHP extensions.

                  Most of these error codes are self - explanatory.   UPLOAD_ERR_INI_SIZE  and  UPLOAD_ERR_FORM_SIZE  are
                 explained in the following section.

                  Limiting the Size of File Uploads

                  Often it ’ s a good idea to prevent unusually large files being sent to the server. Apart from consuming
                 bandwidth and hard disk space on the server, a large file can cause your PHP script to overload the
                 server ’ s CPU. For example, if your PHP script is designed to work on an uploaded 10 - kilobyte text file,
                 uploading a 100 - megabyte text file might cause your script some problems.
              258





                                                                                                      9/21/09   7:23:47 PM
          c09.indd   258                                                                              9/21/09   7:23:47 PM
          c09.indd   258
   291   292   293   294   295   296   297   298   299   300   301