http://qs1969.pair.com?node_id=128564


in reply to Re: using uploadInfo from CGI.pm
in thread using uploadInfo from CGI.pm

Thanks for your attention to this post. Its very appreciated. Unfortunately, it hasnt resolved itself. I've done some testing of my own extrating just the portion of the script that uploads a file and check the content-type printing out the value of $type. It consistantly comes up as undef. My code is now:

sub upload_image { ## pull the file in a variable my $fh = $query->param('upload'); ## determine the file type via the headers my $info = $query->uploadInfo($fh); my $type = $info->{'Content-Type'}; ## take action based on type if ($type =~ m|text/html|i) { ## hash of file names to write to my %destination = ( 'match' => "match.html", 'no_match' => "no_mat +ch.html"); ## open the file to be written open(HTML, ">/path/to/$destination{$formdata{fi lename}}") or die "Cant open HTML file for writing : $!\n"; ## if file is determined to be text/html write contents to appropr +iate locat ion while(<$fh>) { print HTML "$_\n"; } close(HTML); ## otherwise set error for later notification within html } else { $error = "|$type|"; } }

I've tried several different kinds of files, and still to no avail. When I print out the value of $error, i just end up with || making me believe that its being returned as undef. I'm going to keep hammering on it, but I am bewildered as to what is happening.

thanks -c

Replies are listed 'Best First'.
Re: Re: Re: using uploadInfo from CGI.pm
by dws (Chancellor) on Nov 30, 2001 at 11:25 UTC
    If $info->{'Content-Type'} is coming up undef, try
    my $info = uploadInfo($fname); print "uploadInfo:<br>"; map {print " $_: " . $info->{$_} . "<br>\n" } sort keys %$info;
    to see what you are getting.

      Hi. I have the same uploadInfo problem. And if I print the resultant hash of uploadInfo, I print nothing. How come ? Anyone has solved this mystery ?? -- Michel Marcon Sysadmin Unix & WNT michel.marcon@equipement.gouv.fr

        Well well. Never too late is it?

        I tried the same code, and encountered the same problem. It was solved by adding the cgi object to access the upload-member.

        my $cgi = new CGI; my $info = $cgi->uploadInfo( $filename ); print "uploadInfo:<br>"; map {print " $_: " . $info->{$_} . "<br>\n" } sort keys %$info;
        Which in my case gives:
        uploadInfo: Content-Disposition: form-data; name="file";filename="C:\cool\file.t +xt" Content-Type: text/plain

        Elegant use of map in the original snippet, though.