What is the correct function to use for uploading files in PHP?

To upload files in PHP, you should use the move_uploaded_file() function. This function moves an uploaded file to a new location on the server. It takes two parameters: the temporary location of the uploaded file and the destination where the file should be moved to. Make sure to use this function after validating the file and checking for any errors during the upload process.

if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
    $tempFile = $_FILES['file']['tmp_name'];
    $destination = 'uploads/' . $_FILES['file']['name'];
    
    if (move_uploaded_file($tempFile, $destination)) {
        echo 'File uploaded successfully.';
    } else {
        echo 'Error uploading file.';
    }
} else {
    echo 'Error during file upload.';
}