$_FILES is a PHP Super global constant or predefined variable. $_FILES uses an Associative array. $_FILES is HTTP File Upload variables. $_FILES uploaded through the HTTP POST method. When we write a form that uses upload, in that case, we must use enctype form attribute as multipart\form-data. The form method must be POST.
We receive files using the enctype form attribute as multipart\form-data. The $_FILES variable receives data the following way.
$_FILES[‘file’][‘name’]:- This is the name of the file to be uploaded originally.
$_FILES[‘file’][‘type’]:- This holds the mime type of the file.
$_FILES[‘file’][‘size’]:- This is the size of the file to be uploaded in bytes.
$_FILES[‘file’][‘tmp_name’]:- This will include the temporary filename of the file in which the uploaded file was stored on the server.
$_FILES[‘file’][‘error’]:- Any error code associated with the file upload will be saved here.
Example:-
<form action=”” method=”POST” enctype=”multipart/form-data”>
<input type=”file” name=”file”>
<input type =”submit” value=”submit”>
</form>
PHP script part will be:-
<?php
echo “Filename: ” . $_FILES[‘file’][‘name’].”<br>”;
echo “Type : ” . $_FILES[‘file’][‘type’] .”<br>”;
echo “Size : ” . $_FILES[‘file’][‘size’] .”<br>”;
echo “Temp name: ” . $_FILES[‘file’][‘tmp_name’] .”<br>”;
echo “Error : ” . $_FILES[‘file’][‘error’] . “<br>”;
?>