How can PHP developers prevent duplicate image uploads when users refresh or reload the page?

When users refresh or reload a page after uploading an image, the form data is typically resubmitted, causing duplicate image uploads. To prevent this, PHP developers can use a technique called Post/Redirect/Get (PRG) pattern. After processing the form submission, redirect the user to a different page using a header redirect. This way, if the user refreshes the page, only the redirected page will be reloaded, preventing duplicate image uploads.

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Process image upload here

    // Redirect to prevent form resubmission
    header('Location: success.php');
    exit;
}
?>