Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: using uploadInfo from CGI.pm

by dws (Chancellor)
on Nov 30, 2001 at 07:55 UTC ( [id://128541]=note: print w/replies, xml ) Need Help??


in reply to using uploadInfo from CGI.pm

Wild guess (based on comparing your code to my upload code). Instead of
## pull the file in a variable my $fh = $query->upload('upload'); ## determine the file type via the headers my $type = $query->uploadInfo($fh)->{'Content-Type'};
try
## pull the filename in a variable my $fname = $query->param('upload'); ## determine the file type via the headers my $info = $query->uploadInfo($fname); my $type = $info->{'Content-Type'};
I take an extra step, but found that having $info where I could get at it with the debugger paid off (once, which was enough).

Replies are listed 'Best First'.
Re: Re: using uploadInfo from CGI.pm
by c (Hermit) on Nov 30, 2001 at 11:20 UTC
    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

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://128541]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-18 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found