Solved

Perl CGI

Posted on 2004-08-15
13
467 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
 

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now