PHP $_FILES - What is $_ files in PHP ?



  • $_FILES is a superglobal variable of PHP. It is used to upload files from client side to server side.
  • It is a superglobal variable and can be accessed from anywhere in the script.

Examples

$_FILES['file']['name'] //Stores the name of the uploaded file 
$_FILES['file']['type'] //Stores the type of the uploaded file
$_FILES['file']['tmp_name'] //Stores the temporary name of the uploaded file 
$_FILES['file']['error'] //Stores the error code of the uploaded file 
$_FILES['file']['size'] //Stores the size of the uploaded file
php-files

Sample Code

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
	if (isset($_FILES["photo"]) && $_FILES["photo"]["error"] == 0) {
		$file_name	 = $_FILES["photo"]["name"];
		$file_type	 = $_FILES["photo"]["type"];
		$file_size	 = $_FILES["photo"]["size"];
		$file_tmp_name = $_FILES["photo"]["tmp_name"];
		$file_error = $_FILES["photo"]["error"];
		
		echo  $file_name;
		echo "<br>";
		echo $file_type;
		echo "<br>";
		echo $file_size;
		echo "<br>";
       		echo $file_tmp_name;
		echo "<br>";
        		echo $file_error;
	}
}
?>
<!DOCTYPE html>
<html>
<head>
	<title>Wikitechy</title>
</head>
<body>
	<form method="post" enctype="multipart/form-data">
		<h2>Upload File</h2>
		<input type="file" name="photo" id="fileSelect"><br><br>
		<input type="submit" name="submit" value="Upload"><br><br>
	</form>
</body>

</html>

Output

php-files

Related Searches to PHP $_FILES - What is $_ files in PHP ?