Re: uploading files | how to avoid submitting twice?
| From: | George Whiffen | Date: | Sat, 23 Feb 2002 21:28:20 +0000 |
| Subject: | Re: uploading files | how to avoid submitting twice? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-86076@lists.php.net to get a copy of this message | ||
Jim Winstead wrote:
> Andy <news.letters@gmx.de> wrote:
>> Is there a way to redirect imediatelly to a waiting page? I tryed to
>> redirect, but somehow the server is first uploading the file before
>> something else happens.
>
> unfortunately, no. one thing you can do is use javascript to pop up a
> small window in your form's onsubmit method that tells the user to hang
> on, and then close that window in the next page's onload method. it
> isn't easy to do a real progress meter, but even this little bit should
> help tremendously.
>
> you may also want to check the md5 sum of the file contents against
> previous uploads to detect duplicates.
>
> jim
I've never tried it, but it may also be possible to disable the submit
button once it has been pressed once to stop the second upload e.g.
<HTML>
<HEAD>
<SCRIPT LANGUAGE=javascript>
function submitonce()
{
if (document.form.submitted.value == "No")
{
document.form.submitted.value == "Yes";
return true;
} else {
alert("Please wait...");
return false;
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM OnSubmit="return submitonce();">
<INPUT TYPE=HIDDEN NAME=submitted VALUE="No">
<INPUT TYPE=FILE NAME=uploadfile>
<INPUT TYPE=SUBMIT OnClick="return submitonce();">
</FORM>
</BODY>
</HTML>
N.B. I've set the form's OnSubmit and the submit button's onClick, only
because I'm not sure which will work best.
I'd expect this to work with a normal form submit but maybe file upload is
funny...
George