SilverBean
Programmer
Ok so I tackled the uploading concept.
Finally settled on this after all my research
my $upload = $cgi->upload ("targetfilename");
my $binary = '';
while (<$upload>)
{
$binary .= $_;
}
open (OUT, ">$file");
binmode OUT;
print OUT $binary;
close (OUT);
Ok seems a little short, but really it's working fine. My problem came when I tried to make a change to improve it
Actually I wanted to keep track of the size. I know that CGI does support a file size, and also there's the readin thing where you have more control over the size. However the sources I read seemed to suggest there was less chance of hiccups with this and I think the cgi size only worked on certain brower/ client OSs. So just as easy to keep count myself.
My problem was I couldn't count, but now that is fixed and everything is just working fine.
Ok, Ok the punch line. One of my variations on how to break out of the loop if the file reached a certain size was the below:
my $upload = $cgi->upload ("targetfilename");
my $sizeok = 1;
my $binary = '';
while ($sizeok == 1)
{
if (<$upload>)
{
$binary .= $_;
# check size set size = 0 if bad
}
else
{
#normal termination EOF make size bad for now
$sizeok = 0;
}
}
The problem is that $binary nevers gets set to any data from the file. It flows into the true case of the if statement and then does terminate seemingly appropriate for the file size. It's almost like the if (<$upload>) destroys or corrupts $_. but while(<$upload>) does not - Does that make sense?
It's been driving me crazy. Can somebody please tell me why the above is not equivalent to my original. I don't need somebody's implementation of how to do file upload, but I'd like to understand what in Perl's name is going on !!!
Perl 5.8.7, Running Apache 2.0.54, on Windows 2000 Could it be a version/ bug thing?
Finally settled on this after all my research
my $upload = $cgi->upload ("targetfilename");
my $binary = '';
while (<$upload>)
{
$binary .= $_;
}
open (OUT, ">$file");
binmode OUT;
print OUT $binary;
close (OUT);
Ok seems a little short, but really it's working fine. My problem came when I tried to make a change to improve it
Actually I wanted to keep track of the size. I know that CGI does support a file size, and also there's the readin thing where you have more control over the size. However the sources I read seemed to suggest there was less chance of hiccups with this and I think the cgi size only worked on certain brower/ client OSs. So just as easy to keep count myself.
My problem was I couldn't count, but now that is fixed and everything is just working fine.
Ok, Ok the punch line. One of my variations on how to break out of the loop if the file reached a certain size was the below:
my $upload = $cgi->upload ("targetfilename");
my $sizeok = 1;
my $binary = '';
while ($sizeok == 1)
{
if (<$upload>)
{
$binary .= $_;
# check size set size = 0 if bad
}
else
{
#normal termination EOF make size bad for now
$sizeok = 0;
}
}
The problem is that $binary nevers gets set to any data from the file. It flows into the true case of the if statement and then does terminate seemingly appropriate for the file size. It's almost like the if (<$upload>) destroys or corrupts $_. but while(<$upload>) does not - Does that make sense?
It's been driving me crazy. Can somebody please tell me why the above is not equivalent to my original. I don't need somebody's implementation of how to do file upload, but I'd like to understand what in Perl's name is going on !!!
Perl 5.8.7, Running Apache 2.0.54, on Windows 2000 Could it be a version/ bug thing?