Learn about MAX_FILE_SIZE and related errors

Category : General

Facing UPLOAD_ERR_FORM_SIZE error code when uploading a file in the form or webpage? Some of the other errors are discussed below.

UPLOAD_ERR_OKThere is no error, the file uploaded with success.

UPLOAD_ERR_INI_SIZEThe uploaded file exceeds the upload_max_filesize directive in php.ini.

UPLOAD_ERR_FORM_SIZEThe uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.

UPLOAD_ERR_PARTIAL: The uploaded file was only partially uploaded.

UPLOAD_ERR_NO_FILENo file was uploaded.

UPLOAD_ERR_NO_TMP_DIRMissing a temporary folder.

UPLOAD_ERR_CANT_WRITEFailed to write a file to disk.

UPLOAD_ERR_EXTENSIONA PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop.

POST method uploads

This feature lets the user upload both text and binary files. With PHP’s authentication and file manipulation functions, you have full control over who is allowed to upload and what is to be done with the file once it has been uploaded.

File Upload Form

A file upload screen can be built by creating a special form which looks something like this:

<!– The data encoding type, enctype, MUST be specified as below –>
<form enctype=”multipart/form-data” action=”__URL__” method=”POST”>
<!– MAX_FILE_SIZE must precede the file input field –>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”30000″ />
<!– Name of input element determines name in $_FILES array –>
Send this file: <input name=”userfile” type=”file” />
<input type=”submit” value=”Send File” />

The __URL__ in the above example should be replaced, and point to a PHP file.
The MAX_FILE_SIZE hidden field (measured in bytes) must precede the file input field, and its value is the maximum filesize accepted by PHP. This form element should always be used as it saves users the trouble of waiting for a big file being transferred only to find that it was too large and the transfer failed. Keep in mind: bypassing this setting on the browser side is quite easy, so never rely on files with a greater size being blocked by this feature. It is merely a convenience feature for users on the client side of the application. The PHP settings (on the server side) for maximum-size, however, cannot be bypassed.