How does the tmp_name parameter in the $_FILES array relate to the temporary filename of the uploaded file in PHP?

The tmp_name parameter in the $_FILES array contains the temporary filename of the uploaded file in PHP. It is generated by PHP when a file is uploaded and is used to store the file temporarily before it is moved to its final destination. To handle file uploads correctly, you need to move the uploaded file from the temporary location to a permanent location on the server.

// Check if file was uploaded successfully
if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
    $tmp_file = $_FILES['file']['tmp_name'];
    $destination = 'uploads/' . $_FILES['file']['name'];
    
    // Move the uploaded file to its final destination
    if (move_uploaded_file($tmp_file, $destination)) {
        echo 'File uploaded successfully.';
    } else {
        echo 'Failed to move file.';
    }
} else {
    echo 'File upload error.';
}