What is the significance of using $_FILES in PHP when handling file uploads?
When handling file uploads in PHP, using the $_FILES superglobal is essential as it contains information about the uploaded file such as its name, type, size, and temporary location on the server. By accessing this superglobal, you can properly process the uploaded file and move it to the desired location on the server.
// Check if the file was uploaded without errors
if(isset($_FILES['file']) && $_FILES['file']['error'] == 0){
$file_name = $_FILES['file']['name'];
$file_tmp = $_FILES['file']['tmp_name'];
// Move the uploaded file to a new location
move_uploaded_file($file_tmp, "uploads/" . $file_name);
echo "File uploaded successfully!";
} else {
echo "Error uploading file.";
}