Web Hosting Talk







View Full Version : reset of $_FILES array ??


Jimmy99
12-02-2002, 04:16 PM
I'm working on a file upload routine. It uploads fine, except..

The form and the file handling exist within the same php script. I use the regular:

if (is_uploaded_file($_FILES['imgfile']['tmp_name']))
{
// validate and move
} else {
// present user with form, action='$_SERVER[php_self]'
}

Which works fine.

HOWEVER, if I hit F5 on my browser to refresh the page i would expect/like for it to show me the form again. This isn't the case, in fact it seems that IE resends the file and $_FILES gets filled again, thus never going back into the ELSE condition (unless I close the browser and go back).

I've confirmed this by deleting the uploaded file, then hitting F5 and it just appears again.

What's the solution here?

TIA
Jim

sasha
12-02-2002, 04:22 PM
How did you get to that page? You submited the form with post method. So every time you hit f5 you resubmit the form....File is resubmited with the rest of the form and vars are filled in as result of that.

Jimmy99
12-02-2002, 04:42 PM
Well see that's the issue - it RE-submits the form. I don't want it to.

I would like it if, when refreshed, didn't resubmit.

Maybe this is just how it works and there's no simple workaround.

I'm new here but PHP is cool :D

sasha
12-02-2002, 04:54 PM
That is how it works. Has nothing to do with PHP eather.
Only way to be able to reload whithout reposting is to redirect browser after the form is submited
if ( is uploded $_FILES....) {
all nice here
header ("Location: thispage.php
}else{
show them the form
}

Jimmy99
12-02-2002, 08:13 PM
I suspected as much and have adapted my page.

Thanks for taking the time :)