What are common challenges when trying to insert an image on a PHP website?

One common challenge when trying to insert an image on a PHP website is properly handling file uploads and ensuring the image is saved in the correct directory with the correct permissions. Another challenge is correctly displaying the image on the webpage using the correct HTML image tag.

<?php
// Check if a file was uploaded
if(isset($_FILES['image'])){
    $file_name = $_FILES['image']['name'];
    $file_tmp = $_FILES['image']['tmp_name'];
    
    // Specify the directory to save the image
    $upload_dir = "images/";
    
    // Move the uploaded file to the specified directory
    move_uploaded_file($file_tmp, $upload_dir . $file_name);
}
?>

<!-- Display the uploaded image on the webpage -->
<img src="images/<?php echo $file_name; ?>" alt="Uploaded Image">