Value of variable changing before function is finished running

Posted by Patrick on Stack Overflow See other posts from Stack Overflow or by Patrick
Published on 2010-04-14T07:15:15Z Indexed on 2010/04/14 7:23 UTC
Read the original article Hit count: 162

Filed under:

I have an image uploading script in which i use the following setup to assign names to uploaded images;

        $saltdate = date( 'U' );
        $saltuser = $_SERVER[REMOTE_ADDR];
        $saltname = md5($saltdate.$saltuser);

// Recieve, Process, Save uploaded image

// Update database with image name

The problem that i encounter is that after processing/saving the image, when its time to add this file name to the database, the value of $saltdate seems to have changed and i will get a file name in the database that doesnt exist.

How can i make sure that the value doesn't change once i establish it?

© Stack Overflow or respective owner

Related posts about php