What common mistake is being made in the PHP code for uploading images?

The common mistake in the PHP code for uploading images is not checking if the file upload was successful before moving the file to the desired directory. To solve this issue, we need to add a check to verify if the file was uploaded successfully before moving it.

<?php
if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
    $uploadDir = 'uploads/';
    $uploadFile = $uploadDir . basename($_FILES['file']['name']);

    if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) {
        echo "File uploaded successfully.";
    } else {
        echo "Error uploading file.";
    }
} else {
    echo "Error uploading file.";
}
?>