How can the $_FILES array be utilized to handle file uploads more effectively in PHP?

When handling file uploads in PHP, the $_FILES array can be utilized to access information about the uploaded file, such as its name, type, size, and temporary location. By using this array, developers can easily validate and move the uploaded file to the desired location on the server. This allows for more effective handling of file uploads in PHP.

<?php
// Check if file was uploaded without errors
if(isset($_FILES['file']) && $_FILES['file']['error'] == 0){
    $file_name = $_FILES['file']['name'];
    $file_size = $_FILES['file']['size'];
    $file_tmp = $_FILES['file']['tmp_name'];
    
    // Specify the upload directory
    $upload_dir = "uploads/";
    
    // Move the uploaded file to the specified directory
    move_uploaded_file($file_tmp, $upload_dir . $file_name);
    
    echo "File uploaded successfully!";
} else {
    echo "Error uploading file.";
}
?>