How can PHP be used to dynamically create a webpage URL after uploading an image and display the image on that page?

To dynamically create a webpage URL after uploading an image and display the image on that page, you can use PHP to handle the image upload, save the image to a directory on the server, generate a unique URL for the image, and then display the image on the webpage using the generated URL.

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['image'])) {
    $uploadDir = 'uploads/';
    $uploadFile = $uploadDir . basename($_FILES['image']['name']);
    
    if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadFile)) {
        $imageUrl = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $uploadFile;
        echo '<img src="' . $imageUrl . '" alt="Uploaded Image">';
    } else {
        echo 'Failed to upload image.';
    }
}
?>

<form method="post" enctype="multipart/form-data">
    <input type="file" name="image">
    <input type="submit" value="Upload Image">
</form>