What are some best practices for handling file uploads and displaying images in PHP without using a database?

When handling file uploads and displaying images in PHP without using a database, it is important to securely handle file uploads, validate file types, and store the uploaded files in a secure directory on the server. To display images, you can simply reference the file path in the HTML img tag.

<?php
// Handle file upload
if(isset($_FILES['image'])){
    $target_dir = "uploads/";
    $target_file = $target_dir . basename($_FILES["image"]["name"]);
    move_uploaded_file($_FILES["image"]["tmp_name"], $target_file);
}

// Display uploaded image
if(isset($target_file)){
    echo '<img src="'.$target_file.'" alt="Uploaded Image">';
}
?>