How can I properly upload images to a server using PHP?

To properly upload images to a server using PHP, you need to use the $_FILES superglobal array to access the file data, move the uploaded file to a designated folder on the server using move_uploaded_file() function, and handle any errors that may occur during the upload process.

<?php
if(isset($_FILES['image'])){
    $file_name = $_FILES['image']['name'];
    $file_tmp = $_FILES['image']['tmp_name'];
    $file_destination = 'uploads/' . $file_name;

    if(move_uploaded_file($file_tmp, $file_destination)){
        echo 'File uploaded successfully.';
    } else {
        echo 'Error uploading file.';
    }
}
?>