[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 508
  • Last Modified:

Perl CGI

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
TPoly
Asked:
TPoly
  • 5
  • 4
  • 3
  • +1
2 Solutions
 
davorgCommented:
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
 
ahoffmannCommented:
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
 
TPolyAuthor Commented:
how to check for httpd.conf?
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
TPolyAuthor Commented:
how to check for httpd.conf?
0
 
davorgCommented:
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
 
ahoffmannCommented:
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
 
TPolyAuthor Commented:
i found where my httpd.conf
it is at /etc/apache...
so now what should it do????????

thanks
0
 
davorgCommented:
Standard on a RedHat machine seems to be /etc/http/conf/httpd.conf
0
 
davorgCommented:
> so now what should it do????????

Check for the existance of the lines that ahoffman mentioned above.
0
 
TPolyAuthor Commented:
i found this :  SetHandler perl-script

is it related?
0
 
davorgCommented:
No. Not really.

You should really get your Apache server set up by someone who knows what they are doing.
0
 
ronan_40060Commented:
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
 
ahoffmannCommented:
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now