?
Solved

Perl CGI

Posted on 2004-08-15
13
Medium Priority
?
500 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 225 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 150 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans
Suggested Courses

765 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