Solved

Perl CGI

Posted on 2004-08-15
13
480 Views
Last Modified: 2008-03-06
Hi...
i have this cgi code which is suppose to upload file to the internet,
but it don seem to appear in the web browser, instead it show me the code which i've written.
did i place my code at the wrong directory or that this code do not have a html output?
btw i am using perl 5.6.1 and debian linux 3.0

#!/usr/bin/perl

use CGI;

$co = new CGI;

if (!$co->param())
{
      print
            $co->header,

            $co->start_html('CGI File Upload Example').

            $co->center
            (

                  $co->br,
                  $co->center($co->h1('CGI File Uplaod Example')),

                  $co->start_multipart_form,

                  $co->filefield(-name=>'filename', -size=>30),

                  $co->br,
                  $co->submit(-value=>'Upload'),
                      $co->reset,

                  $co->end_form

            ),

            $co->hr;

      }else{
            print

                  $co->header,

                  $co->start_html('CGI File Upload Example'),
                  $co->center($co->h1('CGI File Upload Example'));

            $file = $co->param('filename');

            @data = <$file>;

            foreach (@data) {

                  s/\n/<br>/g;
                  }

            print
                  $co->center($co->h2("Here's the contents of $file...")),

                  "@data";

}

print $co->end_html;

EOF
0
Comment
Question by:TPoly
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 8

Expert Comment

by:davorg
ID: 11807707
Sounds like a web server configuration issue. Your sysadmins should be able to tell how where to put CGI programs on your web server.

Dave...
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 75 total points
ID: 11807801
assuming apache as web server, then check httpd.conf for:

  AddHandler cgi-script .cgi
  AddHandler cgi-script .pl

and there must be a <Directory "/www/cgi-bin"> or alike directive somewhere

Also make shure our script is executbale:
   chmod 555 your-script

Finally I'd ad
  exit(0)
at the end of the script
0
 

Author Comment

by:TPoly
ID: 11807891
how to check for httpd.conf?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:TPoly
ID: 11807892
how to check for httpd.conf?
0
 
LVL 8

Expert Comment

by:davorg
ID: 11807963
We have no way of knowing where your httpd.conf file is installed. It is completely dependent on your system configuration. Your sysadmin should be able to help you.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11807997
more /etc/httpd/httpd.conf
more /usr/local/httpd/conf/httpd.conf
more /usr/local/apache/conf/httpd.conf
# just to mention a few common places
0
 

Author Comment

by:TPoly
ID: 11808070
i found where my httpd.conf
it is at /etc/apache...
so now what should it do????????

thanks
0
 
LVL 8

Expert Comment

by:davorg
ID: 11808077
Standard on a RedHat machine seems to be /etc/http/conf/httpd.conf
0
 
LVL 8

Expert Comment

by:davorg
ID: 11808088
> so now what should it do????????

Check for the existance of the lines that ahoffman mentioned above.
0
 

Author Comment

by:TPoly
ID: 11808294
i found this :  SetHandler perl-script

is it related?
0
 
LVL 8

Expert Comment

by:davorg
ID: 11808627
No. Not really.

You should really get your Apache server set up by someone who knows what they are doing.
0
 
LVL 9

Assisted Solution

by:ronan_40060
ronan_40060 earned 50 total points
ID: 11808822
Hi TPoly
Like ahoffman said
Make sure that in httpd.conf  find AddHandler and remove # sign and add .pl and .cgi like one below
AddHandler cgi-script .cgi .pl
 
the above tells Apache that all files ending with .pl and .cgi should be executed on a server side
 
now save and restart apache

and add the following into ur code
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

save all ur cgi and perl scripts in cgi bin directory of apache
by adding use CGI::Carp qw(fatalsToBrowser); all your errors will be displayed onto the browser and post your result

Good Luck
Ronan
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11809125
forget to mention that the script's name should have extension .pl or .cgi (according my description)

> by adding use CGI::Carp qw(fatalsToBrowser); all your errors will be displayed onto the browser and post your result
in theory, but in praxis you first need to get your script running, then the web server caling the script, then you might see some errors. Obviously first 2 conditions seem not be true so far
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question