From thompson at cns.uni.edu Mon Feb 2 20:44:21 2004
From: thompson at cns.uni.edu (Aaron Thompson)
Date: Mon Aug 2 21:27:33 2004
Subject: [Cedarvalley] upload problem
In-Reply-To: <1071859860.7644.6.camel@localhost.localdomain>
References: <20031211165413.GW28940@faculty.cns.uni.edu>
<20031211195206.GB28940@faculty.cns.uni.edu>
<1071681026.21855.83.camel@localhost.localdomain>
<20031217171535.GA10878@faculty.cns.uni.edu>
<1071698938.21859.382.camel@localhost.localdomain>
<20031219154229.GF10878@faculty.cns.uni.edu>
<1071859860.7644.6.camel@localhost.localdomain>
Message-ID: <20040203024421.GA11241@faculty.cns.uni.edu>
Steve,
Thanks for your help, this ultimately did work. At first it
didn't work... but then I found a problem with my html - my
HTML was off. I had
> ----
>
> upload.cgi
> ----
> #!/usr/bin/perl -w
> use strict;
>
> use CGI;
> my $q = CGI->new;
>
> my $ret = upload($q, 'upload_file',
> { upload_path => './uploads', overwrite => 1 });
>
> print "Content-type: text/html\n\n";
>
> # error?
> if ($ret->{err}) {
> print $ret->{err};
> exit;
> }
>
> # successful
> print<<" EOS";
> $$ret{filename} of size $$ret{length} bytes
> was uploaded.
> EOS
>
> exit 1;
>
> ###########
> # input: query, file upload entry name, Attributes
> # current attributes: upload_path => 'path that files are to be
> uploaded to
> # overwrite => 1 or 0 to replace a file or not
> # output: hash reference of...
> # filename => the final filename that was used for the upload
> # length => the size (in bytes) of the uploaded file
> sub upload {
> my ($q, $file, $attrib) = @_;
>
> # init
> $attrib->{overwrite} ||= 0;
> $attrib->{upload_path} ||= '.'; # current directory
>
> my $output = {};
>
> my ($filename) = ($q->param($file) =~ /.*[\/\\](.*)$/);
> my $FH = $q->upload($file);
>
> # if the file exists and we aren't allowed to overwrite it...
> return {err => 'file exists' }
> if (-e "$$attrib{upload_path}/$filename" &&
> !$attrib->{overwrite});
>
> # upload the file
> $output->{filename} = $filename;
> open (OUTFILE,">$$attrib{upload_path}/$filename") ||
> return {err => "can't create: $$attrib{upload_path}/$filename:
> $!"};
> # should you lock the file here?
> my $buffer;
> binmode(OUTFILE);
> while (read($FH,$buffer,1024)) {
> print OUTFILE $buffer;
> $output->{length} += length($buffer);
> }
> close (OUTFILE);
>
> $output
> }
> ------
>
> On Fri, 2003-12-19 at 09:42, Aaron Thompson wrote:
> > The problem seems to be that it doesn't work with Mozilla 1.5 or IE 6 but works
> > fine with NS 4.7 (I don't have a copy of a new NS browser to test with).
> >
> > Here is the code/html:
> >
> > Thanks for your help.
> >
> >
> > ----------
> > ...
> > sub upload_file{
> > my $overwrite = "1"; #overwrite files on upload (yes = 1, no = 0)
> > my $length = 0;
> > my $file = $query->param("upload-me");
> > my $local_file_name = "";
> > my $uploadFH;
> > my $save_flag;
> >
> > $file =~ s/.*[\/\\](.*)/$1/;
> > $local_file_name = $tmp_dir . "/" .$file;
> > print "File Upload...
This may take some time, please wait...
";
> > print "Attempting to upload: $file
";
> > $save_flag = 1;
> > if(! $overwrite){if( -e $local_file_name ){$save_flag = 0;}}#fi
> > if($save_flag){
> > $uploadFH = $query->upload("upload-me");
> > open UPLOADFILE, ">$local_file_name" or
> > html_die("Could not open $local_file_name for writing!");
> > binmode UPLOADFILE;
> > while ( <$uploadFH> ){
> > print UPLOADFILE;
> > $length += length($_);
> > }#elihw
> > close UPLOADFILE;
> > print "$file of size $length bytes was uploaded.
";
> > }
> > else{
> > print "$file already exists... could not upload.
";
> > }#fi
> > }
> > ...
> > ----------
> >
> > ----------
> >
> >
> > server.domain
> >
> >
> >
> >
> >
> >
> >
> > Upload a gallery for aaron |
> >
> > |
> > |
> >
> >
> > NOTE: The following limitations will apply when using this tool...
> >
> > - this will only work with .zip files
> > - you should not have any spaces in your image files or zip file.
> > - Once you agree to send the data nothing will display untill the transfer is complete.
> >
> >
> >
> > |
> >
> > |
> > |
> >
> >
> > Edit Galleries
> > |
> >
> >
> >
> >
> > ----------
> >
> >
> >
> > On Wed, Dec 17, 2003 at 04:08:58PM -0600, Stephen D. Wells wrote:
> > > If I understand you right it works with netscape but not mozilla... Do
> > > you have a small complete example (including your html) somewhere?
> > >
> > > STEVE
> > >
> > > On Wed, 2003-12-17 at 11:15, Aaron Thompson wrote:
> > > > oh yes... I'm not quite sure what I'm doing wrong.
> > > >
> > > > @
> > > >
> > > > On Wed, Dec 17, 2003 at 11:10:27AM -0600, Stephen D. Wells wrote:
> > > > > I'm back home now and can email again... for some reason the web-based
> > > > > mailer I was using wasn't sending out - I'm back to evolution now though
> > > > > and things are back to normal. Is this still an issue?
> > > > >
> > > > > STEVE
> > > > >
> > > > > On Thu, 2003-12-11 at 13:52, Aaron Thompson wrote:
> > > > > > I have been looking and found that I get different data when
> > > > > > using mozilla 1.5 or Netscape 4... it seems like I don't get
> > > > > > everything... well... back to reading.
> > > > > >
> > > > > > Netscape:
> > > > > >
> > > > > > $VAR1 = bless( {
> > > > > > '.charset' => 'ISO-8859-1',
> > > > > > 'upload-me' => [
> > > > > > bless( \*{'Fh::fh00001new_gallery.zip'}, 'Fh' )
> > > > > > ],
> > > > > > 'submit' => [
> > > > > > 'submit'
> > > > > > ],
> > > > > > 'option' => [
> > > > > > 'add-galleries'
> > > > > > ],
> > > > > > 'gallery' => [
> > > > > > 'New_Gallery'
> > > > > > ],
> > > > > > 'function' => [
> > > > > > 'upload-gallery'
> > > > > > ],
> > > > > > '.tmpfiles' => {
> > > > > > '6' => {
> > > > > > 'info' => {
> > > > > > 'Content-Disposition' => 'form-data; name="upload-me"; filename="new_gallery.zip"',
> > > > > > 'Content-Type' => 'application/x-zip-compressed'
> > > > > > },
> > > > > > 'name' => bless( do{\(my $o = '/var/tmp/CGItemp443')}, 'TempFile' )
> > > > > > }
> > > > > > },
> > > > > > '.parameters' => [
> > > > > > 'option',
> > > > > > 'function',
> > > > > > 'gallery',
> > > > > > 'upload-me',
> > > > > > 'submit'
> > > > > > ],
> > > > > > '.fieldnames' => {}
> > > > > > }, 'CGI' );
> > > > > >
> > > > > > Mozilla 1.5:
> > > > > >
> > > > > > $VAR1 = bless( {
> > > > > > '.charset' => 'ISO-8859-1',
> > > > > > 'upload-me' => [
> > > > > > 'new_gallery.zip'
> > > > > > ],
> > > > > > 'submit' => [
> > > > > > 'submit'
> > > > > > ],
> > > > > > 'option' => [
> > > > > > 'add-galleries'
> > > > > > ],
> > > > > > 'gallery' => [
> > > > > > 'New_Gallery'
> > > > > > ],
> > > > > > 'function' => [
> > > > > > 'upload-gallery'
> > > > > > ],
> > > > > > '.parameters' => [
> > > > > > 'option',
> > > > > > 'function',
> > > > > > 'gallery',
> > > > > > 'upload-me',
> > > > > > 'submit'
> > > > > > ],
> > > > > > '.fieldnames' => {}
> > > > > > }, 'CGI' );
> > > > > >
> > > > > >
> > > > > > On Thu, Dec 11, 2003 at 10:54:13AM -0600, Aaron Thompson wrote:
> > > > > > > I'm using CGI to upload a file... the file box is 'upload-me' and the code
> > > > > > > below works for Netscape 4, but not Mozilla 1.5 or IE 6. Anyone have
> > > > > > > experience with this and can point me in the right direction?
> > > > > > >
> > > > > > > Error message (from apache error log):
> > > > > > > Use of uninitialized value in at /home/httpd/photos/admin/index.cgi line 59.
> > > > > > > readline() on unopened filehandle at /home/httpd/photos/admin/index.cgi line 59.
> > > > > > >
> > > > > > >
> > > > > > > the offending code:
> > > > > > > ------
> > > > > > > use CGI;
> > > > > > > ...
> > > > > > >
> > > > > > > $query = new CGI:
> > > > > > > ...
> > > > > > >
> > > > > > > ######################################################################
> > > > > > > sub upload_file{
> > > > > > > my $overwrite = "0"; #overwrite files on upload (yes = 1, no = 0)
> > > > > > > my %valid_mime = ("zip" => "1");
> > > > > > > my $length = 0;
> > > > > > > my $file = $query->param("upload-me");
> > > > > > > my $local_file_name = "";
> > > > > > > my $uploadFH;
> > > > > > > my $mime;
> > > > > > > my $save_flag;
> > > > > > >
> > > > > > > $file =~ s/.*[\/\\](.*)/$1/;
> > > > > > > if($file =~ /.*[\.](.*)/){$mime = $1;}#fi
> > > > > > > $local_file_name = $tmp_dir . "/" .$file;
> > > > > > > print "File Upload...
This may take some time, please wait...
";
> > > > > > > print "Attempting to upload: $file
";
> > > > > > > if ($valid_mime{$mime}){
> > > > > > > $save_flag = 1;
> > > > > > > if(! $overwrite){if( -e $local_file_name ){$save_flag = 0;}}#fi
> > > > > > > if($save_flag){
> > > > > > > $uploadFH = $query->upload("upload-me");
> > > > > > > open UPLOADFILE, ">$local_file_name" or
> > > > > > > html_die("Could not open $local_file_name for writing!");
> > > > > > > binmode UPLOADFILE;
> > > > > > > while ( <$uploadFH> ){
> > > > > > > print UPLOADFILE;
> > > > > > > $length += length($_);
> > > > > > > }#elihw
> > > > > > > close UPLOADFILE;
> > > > > > > print "$file of size $length bytes was uploaded.
";
> > > > > > > }else{
> > > > > > > print "$file already exists on the server - not uploaded.
";
> > > > > > > }#fi
> > > > > > > }
> > > > > > > else{
> > > > > > > print "File not saved... unallowed file time: $mime
";
> > > > > > > }#fi
> > > > > > > }
> > > > > > >
> > > > > > > ------
> > > > > > >
> > > > > > > Thanks for your help.
> > > > > > >
> > > > > > > @
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Aaron Thompson Unix Systems Administrator, College of Natural Science
> > > > > > > University of Northern Iowa Cedar Falls, IA 50614
> > > > > > >
> > > > > > > "Because as we know, there are known knowns, there are things we know we
> > > > > > > know. We also know there are known unknowns; that is to say we know there are
> > > > > > > some things we do not know. But there are also unknown unknowns - the ones we
> > > > > > > don't know we don't know." - Donald Rumsfeld
> > > > > > > _______________________________________________
> > > > > > > Cedarvalley mailing list
> > > > > > > Cedarvalley@mail.pm.org
> > > > > > > http://mail.pm.org/mailman/listinfo/cedarvalley
> > > > > --
> > > > > Stephen D. Wells
> > > --
> > > Stephen D. Wells
> --
> Stephen D. Wells
--
Aaron Thompson Unix Systems Administrator, College of Natural Science
http://www.cns.uni.edu/~thompson/ University of Northern Iowa
"My doctor says that I have a malformed public-duty gland and a natural
deficiency in moral fiber, and that I am therefore excused from saving
Universes." -Douglas Adams
From thompson at cns.uni.edu Thu Feb 5 15:01:02 2004
From: thompson at cns.uni.edu (Aaron Thompson)
Date: Mon Aug 2 21:27:33 2004
Subject: [Cedarvalley] Checking for a module before loading.
Message-ID: <20040205210102.GI22687@faculty.cns.uni.edu>
Hello,
I was wondering if anyone knew of a good way to check for a
perl module before loading it.
Something like:
use Net::SMTP if (is_module(Net::SMTP));
I would like to write some code that will check if modules are
present and then load them.
Thanks.
@
--
Aaron Thompson Unix Systems Administrator, College of Natural Science
http://www.cns.uni.edu/~thompson/ University of Northern Iowa
"A computer terminal is not some clunky old television with a typewriter in
front of it. It is an interface where the mind and body can connect with the
universe and move bits of it about." -Douglas Adams
From thompson at cns.uni.edu Thu Feb 5 16:13:13 2004
From: thompson at cns.uni.edu (Aaron Thompson)
Date: Mon Aug 2 21:27:33 2004
Subject: [Cedarvalley] Checking for a module before loading.
In-Reply-To: <1076018990.1445.25.camel@localhost.localdomain>
References: <20040205210102.GI22687@faculty.cns.uni.edu>
<1076018990.1445.25.camel@localhost.localdomain>
Message-ID: <20040205221313.GO22687@faculty.cns.uni.edu>
Cool I'll look into these, thanks.
@
On Thu, Feb 05, 2004 at 04:09:50PM -0600, Stephen D. Wells wrote:
> Look at the test scripts for Net::DNS..
>
> ----------------------------
> use Test::More tests => 73;
> use strict;
>
> BEGIN {
> use_ok('Net::DNS');
> use_ok('Net::DNS::Resolver::Recurse');
> use_ok('Net::DNS::Nameserver');
> ---------------------------
>
> it tests whether or not it can load the module...
>
> However...
>
> Module::Load::Conditional
>
> might prove more interesting...
>
> HTH,
> STEVE
>
> On Thu, 2004-02-05 at 15:01, Aaron Thompson wrote:
> > Hello,
> >
> > I was wondering if anyone knew of a good way to check for a
> > perl module before loading it.
> >
> > Something like:
> > use Net::SMTP if (is_module(Net::SMTP));
> >
> > I would like to write some code that will check if modules are
> > present and then load them.
> >
> > Thanks.
> >
> > @
> --
> Stephen D. Wells
--
Aaron Thompson Unix Systems Administrator, College of Natural Science
http://www.cns.uni.edu/~thompson/ University of Northern Iowa
"Because as we know, there are known knowns, there are things we know we
know. We also know there are known unknowns; that is to say we know there are
some things we do not know. But there are also unknown unknowns - the ones we
don't know we don't know." - Donald Rumsfeld