Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display a working Page

Status
Not open for further replies.

paulbenn

Programmer
Jan 24, 2002
108
GB
Hi all,

This is probably simple if you know how, but I don't! I have a script that uploads a file and it works great, however if you upload a large file it appears to be doing nothing whilst the file is uploading in the background. I would like to display a simple HTML page that says "uploading please wait".

I have created a sub routine with the HTML, I call it before the upload Sub but then it displays when the upload is finished along with the "upload complete" page.

Can Some please help me?

Thanks in advance.

Kind Regards, Paul Benn

**** Never Giveup, keep trying, the answer is out there!!! ****
 
I have used a FORK to break the script apart, however it does not give the expected results, it prints both my wait Page and the complete page after the upload has finished and one after the other.

show_progress
{

if (!defined ($pid = fork))
{
die "Unable to fork: $!\n";
}
elsif (! $pid)
{

&do_my_stuff;
&finished_html


exit; # terminate the child process
}
else
{ # this is the branch for the parent
#&parse_form;
&wait_html;
close STDIN;
close STDOUT;
close STDERR;
exit; # terminate the parent process
}

&finished_html;
}

Please somebody help, I am running out of hair to pull out!!!

If you wish to see the output please checkout please only upload small files. Kind Regards, Paul Benn

**** Never Giveup, keep trying, the answer is out there!!! ****
 
Well, the problem is not with your Perl script, but due to the fact that the Perl script is not the program uploading the file. The only way I know to do it is to use a Javascript function that will display a "working" message until the new page is sent to the user. Below is an attempt at such a function, but I've only been able to get it to work in IE 5.0+. Give it a try and if you can get NS 6+ to work with it (I'm not worried about the 4.x versions myself), please post it here. I'd love to have this work cross-browser.

(Please note: I was not the original author of this code)

Code:
<script language=&quot;Javascript&quot;>
// Determine which browser is in use
var agt = navigator.userAgent.toLowerCase();
var IsNetscape = ((agt.indexOf('mozilla') != -1) && ((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1)));
function ShowWorking() {
	if ( IsNetscape ) {
		tid = window.setInterval(&quot;BlinkNS()&quot;, 300);
	} else {
		tid = window.setInterval(&quot;BlinkIE()&quot;, 300);
	}
	return true;
}
function BlinkIE() {
	if ( Working.style.visibility == &quot;hidden&quot; ) {
		Working.style.visibility = &quot;visible&quot;;
	} else {
	Working.style.visibility = &quot;hidden&quot;;
	}
}
function BlinkNS() {
	if ( document.Working.visibility == &quot;hide&quot; ) {
		document.Working.visibility = &quot;show&quot;;
	} else {
		document.Working.visibility = &quot;hide&quot;;
	}
}
</script>
<style type=&quot;text/css&quot;>
.IEworkingClass { position:absolute; left:180px; top:80px;
	padding:10px; color:white; background-color:red;
	font-size:18pt; font-weight:bold; visibility:hidden; }
.NSworkingClass { position:absolute; left:180px; top:80px;
	padding:10px; color:white; background-color:red;
	font-size:18pt; font-weight:bold; visibility:hidden;
	z-index:1}
</style>
Adjust the left and top positioning in the two styles above to get the box to pop up where you want it to.

Put this near the top of the <body> section:
Code:
<script language=&quot;Javascript&quot;>
if ( IsNetscape ) {
	document.writeln(&quot;<DIV id='Working' class='NSworkingClass'>NS WORKING</DIV>&quot;);
} else {
	document.writeln(&quot;<DIV id='Working' class='IEworkingClass'>IE WORKING</DIV>&quot;);
}
</script>
And in your <form> tag add this:

Code:
onSubmit=&quot;return ShowWorking()&quot;
 
Here is another approach that has some admitted short
comings. Short coming number 1: it does not work with
IE. It does work with NN4.7, NN7, and mozilla. Short
coming number 2: &quot;who needs another with a number 1 like
that?&quot;. I thought it was kinda' cool, anyway.

The piece of code spawn three child processes, sends
an update to the browser as it listens to each child
report and then refreshes the page with the results
reported by all the children.

Code:
#!/usr/local/bin/perl
use CGI qw/:push -nph/;

my ($pid, $cmd, $handles, $sleep, @results);
my @cmds = ('CMD1','CMD2','CMD3');
my $num_cmds = @cmds;
$| = 1;

foreach my $i (@cmds)
    {
    $sleep++;
    $cmd = $i;
    # spawn a child using the '-|' pipe syntax
    last if (!($pid = open($cmd,&quot;-|&quot;))); # bail out if child process
    }

if ($pid) # $pid exists - this is the parent process
    {
    print multipart_init(-boundary=>'--------!');
    foreach my $i (@cmds)
        {
        print multipart_start(-type=>'text/html');
        $handles++;
        print qq(<p>Searching handle $i, $handles out of $num_cmds, $return</p>);
        while ($return = <$i>) 
            {
            print &quot;Got $return<br />&quot;;
            push @results, $return;
            }
        print multipart_end;
        }
    $| = 0; # turn autoflush off
    }

if (!($pid)) # this is a child process
    {
    # some trivial output from child throug STDOUT to the parent
    for $num (0..3)
        {
        print &quot;--- Child Process: $sleep VAL: $num ---\n&quot;;
        sleep $sleep;
        }
    exit;
    }

print multipart_start(-type=>'text/html');
print '<h2>RESULTS</h2><pre>';    
foreach $element (@results) { print qq(<p>$element</p>\n); }
print '</pre><h2>END</h2>';
print multipart_end;


I don't think you'd want to use this for a public web page, but someone might have use for it in an intranet. My office is standardized on Netscape, so it works here. 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Thanks, but I agree with a number 1 like that who needs to say anymore...

I am trying to write it for general release, so need it to work with IE i am affraid!

Kind Regards, Paul Benn

**** Never Giveup, keep trying, the answer is out there!!! ****
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top