1 #!/usr/bin/perl -wT
2
3 use strict;
4 use CGI qw(:standard);
5
6 my $q = new CGI;
7
8 my $filename = $q->param('/home/yifangt/hello.cgi');
9 my $contenttype = $q->uploadInfo($filename)->{'Content-Type'};
10
11 print header;
12 print start_html;
13 if ($contenttype !~ /^text\/html$/) {
14 print "Only HTML is allowed<P>";
15 print end_html;
16 exit;
17 } else {
18
19 print "Type is $contenttype<P>";
20 }
21
22 print end_html;
23
The error message from my /var/apache2/error.log is:
Use of uninitialized value $filename in scalar dereference at (eval 3) line 3.
Use of uninitialized value in hash element at (eval 3) line 3.
Can't use an undefined value as a HASH reference at /usr/lib/cgi-bin/Listing4-2.cgi line 9.
[Wed Dec 28 11:37:10 2011] [error] [client 127.0.0.1] Premature end of script headers: Listing4-2.cgi
I was wondering why Line 9 was of problem
9 my $contenttype = $q->uploadInfo($filename)->{'Content-Type'};
which actually looks fine. It can't be Line 3 which is a routine perl line:
3 use strict;
Have spent some time on this, could not figure out the reason. Appreciate any clues on this from a cgi beginner. Thanks a lot! Happy New Year!!
Thanks Dave!
Actually I copied from the book which was working from the context. I did not catch the whole thing.
Then how to correct this error, which would help me understanding, if possible?
Thanks again.
I changed the line to what you suggested, but it still did not work.
The syntax seems fine to me, even the original version. I must have missed something about MySQL configuration, or basic concepts. Appreciate any advise.
Yifang
What happens if you make a (or move the) file called "hello.cgi" and put it inside /usr/lib/cgi-bin/ and then change the line to:
my $filename = 'hello.cgi';
I don't think this has anything to do with your MySQL config. If this fails, hopefully someone with more knowledge than me can be able to help you out.