<!--
[FormFields]
WB_AllowMultipart=T
WB_FULID=$wbif{"$wbv{image}"=""|t|f}
[Upload]
WB_Disallow=![jpg,gif]
WB_MaxFSize=10485760
-->
<!--WB_BeginTemplate-->
<html>
<head>
<title>$wbif["$wbv[image]"=""|Upload file|File uploaded]</title>
</head>
<body>
$wbif["$wbv[image]"=""|
<form action="$wbe[script_name]" method="post" ENCTYPE="multipart/form-data" id="UploadForm">
Select file (*.jpg;*.gif - max. 10MB): <input type="file" name="image" size="20">
<input type="submit" name="sButt" value="Upload" onclick="window.open('progress.wbsp?fid=$wbfulid[]','','width=200,height=100,toolbar=0,menubar=0,location=0,scroolbars=0');document.getElementById('UploadForm').submit();">
</form>
|
Open uploaded image<br><a href="$wbv[image]" target="_blank">$wbv[image]</a><br>
]
</body>
</html>
<html>
<head>
<meta http-equiv="refresh" content="1;url=$wbe[script_name]?fid=$wbv[fid]&pp=$wbcalc[$wbfup[$wbv[fid]]/$wbfut[$wbv[fid]]*100]">
</head>
<script language="javascript">
if($wbcalc[$wbfup[$wbv[fid]]/$wbfut[$wbv[fid]]*100]==0 && $wbv[pp]>0){window.close();}
window.focus(); #* Bring progress window on top upon reloading. To make this work in FireFox you must have "Allow scripts to: raise or lower windows" checked in advanced JavaScript preferences *#
</script>
<body>
Uploaded: $wbformat[$wbcalc[$wbfup[$wbv[fid]]/$wbfut[$wbv[fid]]*100]|0.00] %
</body>
</html>
WB_FULID=$wbif{"$wbv{image}"=""|t|f}
You notice decision structure ($WBIF) in a content of this variable setting its value to true only if form variable named “image” is empty. This is because we need to set WB_FULID (BTW – it is acronym for Form Upload ID) to true when upload form is opened, but before upload starts. This will set a unique ID for a particular form and a particular browser and that ID will be sent to the server together with form data so it will be used by WhizBase to save the progress info. Generated ID value can be retrieved using function $wbfulid[], and as you can see in the following line:
<input type="submit" name="sButt" value="Upload" onclick="window.open('progress.wbsp?fid=$wbfulid[]','','width=200,height=100,toolbar=0,menubar=0,location=0,scroolbars=0');document.getElementById('UploadForm').submit();">
We use it to pass form upload id to script progress.wbsp as variable named “fid”. This variable will be used in script progress.wbsp to retrieve progress data for exact upload session from WhizBase server.
Uploaded: $wbformat[$wbcalc[$wbfup[$wbv[fid]]/$wbfut[$wbv[fid]]*100]|0.00] %
Function
$wbformat is used for showing progress percentage in proper format, and
$wbcalc is used to calculate the percentage. But the real thing is retrieved by these two functions –
<meta http-equiv="refresh" content="1;url=$wbe[script_name]?fid=$wbv[fid]&pp=$wbcalc[$wbfup[$wbv[fid]]/$wbfut[$wbv[fid]]*100]">
but therefore we had to close the window upon completion to avoid unnecessary traffic.
if($wbcalc[$wbfup[$wbv[fid]]/$wbfut[$wbv[fid]]*100]==0 && $wbv[pp]>0){window.close();}
so you can see a great example of mixing WhizBase code with JavaScript – “if” command on the left is still standard JavaScript statement, but it contains server-side WhizBase code that will never reach the client. Actually what the browser will receive is something like:
if(25.5==0 && 23.91>0){window.close();}
and will not close the window until it receives:
if(0==0 && 100>0){window.close();}
which will mean that upload is finished and progress data for upload session with particular form upload id is deleted. We added form variable “pp” ($wbv[pp]) to avoid closing progress window at the very beginning (with large files and slower connection you'll get 0% uploaded for first few seconds).
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)