Ok I have been trying for hours and hours to stop my image upload script from uploading the same image whenever a user refreshes the page.

I have tried unlink, unset and redirecting the user and back. It still won't quit. I have literally unset every single input element in my script but the form still submits the previous image when the page is refreshed.

I was told to use unlink by someone but unlink just returns the following error:

Warning: unlink() [function.unlink]: No error in c:\program files\....

I even tried to attach a user submitted validation to the script by making them solve a simple addition question but even this didn't work because for some reason unset didn't stop the variables from being removed.

Try using sessions or cookies so php can remember weather the uploader has been processed.

after the user submitted the form, and the textfield and file upload field has filled, insert into the table, and use redirect:

header("Location: success.php");

another way, is to implement a refresh check used by the submit time.

add a hidden field into the form:

<input type="hidden" name="hiddentime" value="<?php echo time();?>">

if submit has pressed:

<?php
session_start();

if(!empty($_POST["submit"]))
{
    if ( empty( $_POST["hiddentime"] ) ) {
        die( "timestamp is missing!" );
    } else {
        $hidd = $_POST["hiddentime"];
        if ( isset( $_SESSION["time_$hidd"] ) )
            die("Do not refresh the page!");
        else
            $_SESSION["time_$hidd"] = 1;
    }

//the rest of the code
}

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.