Checking
for Errors

One
important thing that you should know is how to check whether there
are any errors during the extraction of uploaded files from an HTTP
request. If an error has occurred, PHP will set an error code, which
can be retrieved using the following line of script (here we assume
that the name attribute of
the <input type="file"> element is myFile):

$errorCode
= $_FILES['myFile']['error'];

If
everything works fine, the value of $errorCode will be equal to the
UPLOAD_ERR_OK constant. If there is an error, the value of $errorCode
will be equal to one of the following constants:

UPLOAD_ERR_INI_SIZE
Error Code

The
UPLOAD_ERR_INI_SIZE error code means the size of the uploaded file is
larger than the value specified by the upload_max_filesize
directive.

UPLOAD_ERR_FORM_SIZE
Error Code (Use with the MAX_FILE_SIZE Form Field)

The
UPLOAD_ERR_FORM_SIZE error code never appears if there is no
MAX_FILE_SIZE hidden field in the HTML/XHTML form that contains the
<input type="file"> element.

In
the above HTML/XHTML code, the MAX_FILE_SIZE form field states that
the file to be uploaded should not be larger than 1048576 bytes. If a
browser supports this form field, it will not allow the user to
choose a file that is larger than 1048576 bytes. So, the user does
not have to wait for a file to upload to the server in order to find
out whether it is too large or not. However, at the time of writing,
we cannot find any WAP browsers that support the MAX_FILE_SIZE form
field. Also, both IE 6 and Firefox 2.0 do not understand this form
field.

No
matter whether a web / WAP browser understands the MAX_FILE_SIZE form
field or not, if the PHP engine finds that the uploaded file's size
is larger than the value specified by the MAX_FILE_SIZE form field,
it will give the error code UPLOAD_ERR_FORM_SIZE.

It
is important to note that the MAX_FILE_SIZE field value can easily be
modified at the client-side. So, the MAX_FILE_SIZE form field is not
a reliable way to restrict the size of uploaded files. A better way
is to use the upload_max_filesize
directive, which is mentioned in "PHP
Directives Related to (Large) File Upload"
of this tutorial.

Note
that the <input type="file"> element must be placed
after the MAX_FILE_SIZE form field.

UPLOAD_ERR_PARTIAL
Error Code

The
UPLOAD_ERR_PARTIAL error code means the server only receives part of
the uploaded file.

What do you think about this web page? It is very helpful. It is helpful, but some information I wanted is missing. It is not helpful. It has broken links. It has typos / grammatical mistakes. It has incorrect information. Others

(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Due to the amount of messages we received, we may not be able to reply to all messages.