$_FILES¶
In PHP, the $_FILES
variable is a special superglobal variable that is used to retrieve information about files uploaded to the server via HTML forms with the enctype="multipart/form-data"
attribute. It provides access to the uploaded file’s properties such as name, size, type, and temporary location on the server.
When a file upload form is submitted, PHP populates the $_FILES
variable with an array structure that contains information about the uploaded files. The array is organized based on the input field names used in the form.
$_FILES['userfile']['name']
: the original name of the file on the client machine.$_FILES['userfile']['type']
: the mime type of the file, if the browser provided this information. An example would be “image/gif”. This mime type is however not checked on the PHP side and therefore don’t take its value for granted.$_FILES['userfile']['size']
: the size, in bytes, of the uploaded file.$_FILES['userfile']['tmp_name']
: the temporary filename of the file in which the uploaded file was stored on the server.$_FILES['userfile']['error']
: the error code associated with this file upload.$_FILES['userfile']['full_path']
: the full path as submitted by the browser. This value does not always contain a real directory structure, and cannot be trusted. Available as of PHP 8.1.0.
$_FILES
is associated to the functions move_uploaded_file() and is_uploaded_file().
<?php
// $a->file was filled with $_FILES at some point
move_uploaded_file($a->file['tmp_name'], $target);
?>
See also POST method uploads
Related : File Upload, $_GET, $_COOKIE, $_ENV, $_SERVER, File Upload, Incoming Data