How can a beginner effectively upload or copy a photo from a PHP page?

To upload or copy a photo from a PHP page, a beginner can use the move_uploaded_file() function to move the uploaded file to a specified directory on the server. This function takes two parameters: the temporary location of the uploaded file and the destination where the file should be moved to. By using this function, the beginner can effectively handle file uploads in PHP.

$target_dir = "uploads/"; // specify the directory where the file should be saved
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); // get the file name

if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
    echo "Sorry, there was an error uploading your file.";
}