Re: Why is not the window printed?

2002-08-01 Thread zentara

On Thu, 01 Aug 2002 11:40:49 -0400, [EMAIL PROTECTED] (Zentara)
wrote:

Hi again, just to tell you I've had better luck with your
script. I tried to flush the stdout when printing "."

I think the secret is to force a buffer flush with \n.

I tried :
select STDOUT; $|=1;
print STDOUT ".";

but it still buffered the dots when used over a LAN.

I finally got it to work over my LAN with the
following changes. I broke the while loop
that does the reading up, so that each read
is a separate event.

Then I put a \n after the "."   i.e. print ".\n".
Even then the dots came out a line at a time.
So I tried  print "still uploading\n".
That does it, but it scrolls off bottom of screen.
Anyways, it should work.

The below script works, but you get an awful
lot of messages, but it depends on file size.
Anyways, it was fun trying to figure this out. :-)


#!/usr/bin/perl -wT
use strict;
use CGI;

my $q = new CGI;

#The max size of the uploaded file:
$CGI::POST_MAX = 1024 * 1024 * 30;
my $maxfile = $CGI::POST_MAX;

#The folder with the uploaded files:
my $outfolder = "uploads";

&upload;

sub upload {
my ($filen, $ext);

#Print the start of the page:
$| = 1;
print <
eof

my $file = $q->upload('file');

my $filename = $file;
$filename =~ s/^.*\///g;
$filename =~ s/^.*\\//g;

$filename =~ s/\-/_/g;
$filename =~ s/^\.*//g;
$filename =~ s/ /_/g;
my $allpath = $file;

if ($filename =~ /\./) {
$filen = $`;
$ext = $';
}

my $maxtries=4;
for (my $i=1; $i < $maxtries; $i++) {
if (-e "$outfolder/$filename") {
$filename = $filen . "_" . $i . '.' . $ext;
}
}

#Create the file on the server, and print the "." on the page:
open(OUT, ">$outfolder/$filename")
or die "Can't open $outfolder/$file for writing. - $!";
binmode OUT;
while(1){ 
#while(read($file, my $buffer, 1024)){;
read($file, my $buffer,4096);
last unless $buffer;
print OUT $buffer;
print ".still uploading\n";
select (undef,undef,undef,.01);
}
close OUT;

my $filesize = -s "$outfolder/$filename";
$filesize = (int(($filesize / 1024) * 10) / 10);
$filesize = "$filesize KB";

#Print on the browser:
my $script = 'http://zentara.zentara.net/~zentara/up2.html';
print <
The file $filename was successfully uploaded!
The file has $filesize.

Go back if you want to upload one more file.
   
Go to main page on Teddy Center!

eof

#End the subroutine
}

   



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Why is not the window printed?

2002-08-01 Thread zentara

On Wed, 31 Jul 2002 15:17:56 +0300, [EMAIL PROTECTED] (Octavian Rasnita)
wrote:

>I want to print another page that prints "File uploading..." while the file
>is uploading.
>
>Unfortunately I can't do that.
>After pressing the upload button, the page remains the same. It only appears
>"Opening Page..." in the task bar.
>
>Only after the file is uploaded it prints the result page, even a part of
>that page is printed before opening and printing the file.
>
>Do you have any idea why?

Well I had to chop down, and slow your script up, to get it to run
for me. 
I'm running this on my localhost, so I can't guess what happens over
a serial connection. 
I'm guessing that your script is running so fast on the localhost, that
everything appears "at once". I put a "select(undef,undef,undef,.05)"
in there, so the dots would flow. I also had to reduce your buffer size
to get more dots to appear.  If you need to resort to these tricks to
get it to work over a serial connection, I'm afraid all you are doing is
slowing down your uploads, maybe you shouldn't use the upload
progress meter?  Like I said, this runs on my localhost, showing
progress, but when I try the script from a machine on my LAN, 
it prints all the dots at once. There is probably buffering going on
in the ethernet system.  This is way too unpredictable to use.

#up2.cgi
###
#!/usr/bin/perl -wT
use strict;
use CGI;

my $q = new CGI;

#The max size of the uploaded file:
$CGI::POST_MAX = 1024 * 1024 * 30;
my $maxfile = $CGI::POST_MAX;

#The folder with the uploaded files:
my $outfolder = "uploads";

&upload;

sub upload {
my ($filen, $ext);

#Print the start of the page:
$| = 1;
print 
  Uploading the file...




The file is uploading...


eof

my $file = $q->upload('file');

my $filename = $file;
$filename =~ s/^.*\///g;
$filename =~ s/^.*\\//g;

$filename =~ s/\-/_/g;
$filename =~ s/^\.*//g;
$filename =~ s/ /_/g;
my $allpath = $file;

if ($filename =~ /\./) {
$filen = $`;
$ext = $';
}

my $maxtries=4;
for (my $i=1; $i < $maxtries; $i++) {
if (-e "$outfolder/$filename") {
$filename = $filen . "_" . $i . '.' . $ext;
}
}

#Create the file on the server, and print the "." on the page:
open(OUT, ">$outfolder/$filename")
or die "Can't open $outfolder/$file for writing. - $!";
binmode OUT;
binmode $file;
while (read($file, my $buffer, 1024)) {
print OUT $buffer;
#Print to the browser to prevent the timeout:
print  ".";
select (undef,undef,undef,.05);
}
close OUT;

my $filesize = -s "$outfolder/$filename";
$filesize = (int(($filesize / 1024) * 10) / 10);
$filesize = "$filesize KB";

#Print on the browser:
my $script = 'http://zentara.zentara.net/~zentara/up2.html';
print <
The file $filename was successfully uploaded!
The file has $filesize.

Go back if you want to upload one more file.
   
Go to main page on Teddy Center!

eof

#End the subroutine
}
###

#up2.html
##

http://zentara.zentara.net/~zentara/cgi-bin/up2.cgi>

 


##

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Why is not the window printed?

2002-07-31 Thread Octavian Rasnita

Hi all,

I've made a script for uploading a file, and it uploads the file but it has
a problem.

I want to print another page that prints "File uploading..." while the file
is uploading.

Unfortunately I can't do that.
After pressing the upload button, the page remains the same. It only appears
"Opening Page..." in the task bar.

Only after the file is uploaded it prints the result page, even a part of
that page is printed before opening and printing the file.

Do you have any idea why?

Thank you.

Here is the script:

#!/usr/bin/perl -WT

=author Teddy;
Script made by Octavian Rasnita [EMAIL PROTECTED]
=cut

use lib "/var/www/teddy/lib";

use strict;
use CGI;

my $q = new CGI;

#The max size of the uploaded file:
$CGI::POST_MAX = 1024 * 1024 * 30;
my $maxfile = $CGI::POST_MAX;

#The folder with the uploaded files:
my $outfolder = "/var/www/teddy/html/up";

my $hostroot = $ENV{'HTTP_HOST'};
#The web address of the folder with uploaded files:
my $web_folder = "http://$hostroot/up";;

#The max size of the directory with uploaded files
my $maxfolder = 1024 * 1024 * 100;

#Max number of retries to rename (incrementing) the file:
my $maxtries = "20";

#Should this script announce  by mail about this upload?
my $sendmail = 1;

#The email address used for announcing this upload:
my $email_address = '[EMAIL PROTECTED]';

#The sender address of this message:
my $email_from = '[EMAIL PROTECTED]';

#The address of the SMTP mail server:
my $server = '127.0.0.1';

#The Hello address:
my $hello = "localhost";

#The path to the sendmail program:
my $mailprog = "/usr/sbin/sendmail";

#The subject of the message:
my $email_subject = 'New file uploaded!';

### End editing ###

my $screen = $q -> param ('screen');
my $script = $ENV{'SCRIPT_NAME'};
my $name = $q -> param ('name');
my $email = $q -> param ('email');
my $comments = $q -> param ('comments');
my $filename;
my $allpath;
my $filesize;
my $host;
### Start code ###

my $dirsize = dir_size($outfolder);
my $content_length = $ENV{'CONTENT_LENGTH'};
if (! $content_length) {
$content_length = 0;
}
my $filled_space = $dirsize + $content_length;

if ($content_length > $maxfile) {
#If the size of the file is bigger than the max size of a file that is
allowed:
my $freespace = $maxfile;
$freespace = int(($freespace / 1048576) *10)/10;

print "Content-type: text/html\n\n";
print ask me how to do it.

eof

exit;
#End if:
}

if ($filled_space > $maxfolder) {
#If the size of the file + size of folder  is bigger than the max allowed
size of folder:
my $freespace = $maxfolder - $dirsize;
$freespace = int(($freespace / 1048576) *10)/10;

print "Content-type: text/html\n\n";
print ask me how to do it.

eof

exit;
}

if (! $screen) {
&print_form;
}
elsif($screen eq "1") {
&get_host;
&upload;
if ($sendmail eq "1") {
&send_mail;
}
}

sub print_form {
print "Content-type: text/html\n\n";

my $freespace = $maxfolder - $dirsize;
if ($freespace > $maxfile) {
#Daca e loc mai mult decat marimea maxima a unui fisier permis:
$freespace = $maxfile;
$freespace = int(($freespace / 1048576) *10)/10;
}
else {
#Daca e loc mai putin decat marimea unui fisier:
$freespace = int(($freespace / 1048576) *10)/10;
}

print ask me how to do it.

You don't need to fill all the fields. You need just to type the correct
path to a file you want to upload.

You can leave all the other fields blank if you want, but I would recommend
filling them.

If you are using a screen reader, and if it can't read the "Browse" button,
you have to activate the forms mode, then press tab, then space bar.
This will open the "Browse for file" window


File name:
Your name: 
Your email: 
Comments: 




eof
#end sub print_form:
}

sub upload {
my ($filen, $ext);

#Print the start of the page:
$| = 1;
print 
  Uploading the file...





The file is uploading...


eof

my $file = $q->upload('file');

$filename = $file;
$filename =~ s/^.*\///g;
$filename =~ s/^.*\\//g;

$filename =~ s/\-/_/g;
$filename =~ s/^\.*//g;
$filename =~ s/ /_/g;
$allpath = $file;

if ($filename =~ /\./) {
$filen = $`;
$ext = $';
}

for (my $i=1; $i < $maxtries; $i++) {
if (-e "$outfolder/$filename") {
$filename = $filen . "_" . $i . '.' . $ext;
}
}

#Create the file on the server, and print the "." on the page:
open(OUT, ">$outfolder/$filename")
or die "Can't open $outfolder/$file for writing. - $!";
binmode OUT;
binmode $file;
while (read($file, my $